﻿/******************************************************************
 *                  Dipan.SanGuo Global Utils                     *
 *                                                                *
 * File Name: Global.js                                           *
 * Written by: yangc (sheepchang@163.com)                         *
 * Important: to use this script don't                            *
 * remove these comments                                          *
 * Version 1.0 (MSIE 6.0 above,Firefox2.0,Netscape.)              *
 * Created Date: 2008-05-30                                       *
 ******************************************************************/

var Dipan = new Object();
Dipan.SanGuo = new Object();
Dipan.SanGuo.Plus = new Object();
/* 公共函数 */
Dipan.SanGuo.Common =
{
    Initialize: function()
    {
        var Loader = new Dipan.SanGuo.Common.Loader();
        Loader.onsuccess = function()
        {
        }
		Loader.js(Dipan.SanGuo.Common.StaticsServer + "/@/JavaScripts/Prototype.js",true);
    },
    
    ChatServer: "",
    
    ChatPort: 0,
    
    RequestServer: "",
    
    StaticsServer: ".",
    
    MapPic: "",
    
    NavPic: "",
    
    Loader: function()
    {
         /**
          * 按需加载JS文件
          * @param {url} 要加载的JS文件地址
          * @param {finish} 是否执行成功方法
          * @type Object
          */
         this.js = function(url,finish)
         {
            var ss = document.getElementsByTagName("SCRIPT");
            
            for (i = 0; i < ss.length; i++)
            {
                if (ss[i].src && ss[i].src.indexOf(url) != -1)
                {
                    if (finish)
                    {
                        this.onsuccess();
                        return;
                    }
                    return;
                }
            }
            
            s = document.createElement("SCRIPT");
            s.type = "text/javascript";
            s.src = url + "?t=20081106000000.js";
            var head = document.getElementsByTagName("HEAD")[0];
            head.appendChild(s);
            
            var self = this;
            
            if (navigator.userAgent.indexOf("Chrome") > 0)
            {
                self.onsuccess();
                return;
            }
            
            s.onload = s.onreadystatechange = function()
            {
                if (this.readyState && this.readyState == "loading") 
                {
                    return;
                }
                else
                {
                    if (finish)
                    {
                        self.onsuccess();
                        return;
                    }
                    return;
                }
            }
            
            
            
            s.onerror = function()
            {
                head.removeChild(s);
                self.onfailure();
            }
        }
        
        /**
          * 按需加载CSS文件
          * @param {url} 要加载的CSS文件地址
          * @param {finish} 是否执行成功方法
          * @type Object
          */
        this.css = function(url,finish)
        {
            var ss = document.getElementsByTagName("LINK");
            
            for (i = 0; i < ss.length; i++)
            {
                if (ss[i].src && ss[i].src.indexOf(url) != -1)
                {
                    if (finish)
                    {
                        this.onsuccess();
                        return;
                    }
                    return;
                }
            }
            
            s = document.createElement("LINK");
            s.type = "text/css";
            s.rel = "stylesheet";
            s.href = url + "?" + Math.random();
            var head = document.getElementsByTagName("HEAD")[0];
            head.appendChild(s);
            
            var self = this;
            s.onload = s.onreadystatechange = function()
            {
                if (this.readyState && this.readyState == "loading") 
                {
                    return;
                }
                else
                {
                    if (finish)
                    {
                        self.onsuccess();
                    }
                }
            }
            
            s.onerror = function()
            {
                head.removeChild(s);
                self.onfailure();
            }
        }
        
        this.onsuccess = function(){};
            
        this.onfailure = function(){};
    },
    
    /**
      * 正在加载
      * @param {domid} DOM ID
      * @param {msg} 提示消息
      * @type Object
      */
    Loading: function(domid, msg)
    {
        var Loader = new Dipan.SanGuo.Common.Loader();
        
        Loader.onsuccess = function()
        {
            var o = $(domid);
            var loading = $("loading");
            if (o)
            {
                if (loading == undefined && msg != undefined)
                {
                    var dw = o.offsetWidth?o.offsetWidth:o.width;
                    var dh = o.offsetHeight?o.offsetHeight:o.height;
                    var createloading = function()
                    {
                        var loading = document.createElement("div");
                        loading.id = "loading";
                        loading.style.fontSize =  "12px";
                        loading.style.position = "absolute";
                        loading.style.width = dw + "px";
                        loading.style.height = dh + "px";
                        loading.style.left = "0px";
                        loading.style.top = "0px";
                        loading.style.display = "none";
                        loading.style.overflow = "hidden";
                        loading.style.textAlign = "center";
                        loading.style.zindex = "1103754";
                        loading.innerHTML= "<div style=\"position:absolute;left:"+(dw/2-60)+"px;top:"+(dh/2-40)+"px;\"><img src=\""+Dipan.SanGuo.Common.StaticsServer +"/@/Images/loading.gif\" border=\"0\" />"+(msg==undefined?"正在加载...":msg)+"</div>";
                        o.style.position = "relative";
                        o.appendChild(loading);
                        return loading;
                    };
                    this.Loadings = createloading();
                    this.Loadings.style.display = "block";
                    new Effect.Opacity("loading", {from:0.4, to:0.4});
                    return this.Loadings;
                }
                else
                {
                    o.removeChild(loading);
                }
            }
        }
        
        Loader.js(Dipan.SanGuo.Common.StaticsServer + "/@/JavaScripts/Prototype.js",true);
    },
    
    /**
     * 获取页面查询参数
     * @param {name} 查询参数名
     * @type String
     */
    GetQueryString: function(name)
    {
        var result = "";
	    var querystr = GetValue().split("&");
	    for(var i = 0; i < querystr.length; i++)
	    {
		    var sb = querystr[i].split("=");
		    if(sb[0].toLowerCase() == name.toLowerCase())
		    {
			    result = sb[1];
			    break;
		    }
	    }
	    return result;
    },
    
    /**
     * 获取页面查询参数
     * @type String
     */
    GetValue: function()
    {
        var i = document.location.href.indexOf("?");
	    if(i >= 0)
	    {
		    return document.location.href.substr(i + 1);
	    }
	    else
	    {
		    return "";
	    }
    },
    
    /**
     * 设置Cookie
     * @param {name} Cookie名
     * @param {value} Cookie值
     * @param {option} Cookie选项
     */
    SetCookie: function(name,value,option)
    {
        var str = name + "=" + escape(value);		
	    if(option)
	    {
		    if(option.expireDays)
		    {
			    var date = new Date();
			    var ms = option.expireDays * 24 * 3600 * 1000;
			    date.setTime(date.getTime() + ms);
			    str += "; expires=" + date.toGMTString();
		    }
		    if(option.expireMinutes)
		    {
			    var date = new Date();
			    var ms = option.expireMinutes * 60 * 1000;
			    date.setTime(date.getTime() + ms);
			    str += "; expires=" + date.toGMTString();
		    }	
		    if(option.path)str += "; path=" + option.path;
		    if(option.domain)str += "; domain=" + option.domain;
		    if(option.secure)str += "; true";
	    }
	    
	    document.cookie = str;
    },
    
    /**
     * 获取Cookie
     * @param {name} Cookie名
     * @type String
     */
    GetCookie: function(name)
    {
        var cookieArray = document.cookie.split("; ");
	    var cookie = new Object();
	    for(var i=0; i< cookieArray.length; i++)
	    {
		    var arr = cookieArray[i].split("=");
		    if(arr[0] == name)
		    {
			    return unescape(arr[1]);
		    }
	    }
	    return "";
    },
    
    /**
     * 获取Cookie
     * @param {name} Cookie名
     */
    DelCookie: function(name)
    {
	    SetCookie(name, "",{expireDays:-1});
    },
    
    /**
     * 列表页面跳转
     * @param {baseurl} 页面
     * @param {max} 最大页码
     */
    ChangePage: function(baseurl,max)
    {
        var Loader = new Dipan.SanGuo.Common.Loader();
        
        Loader.onsuccess = function()
        {
            var cp = parseInt($("GotoPage").value);
	        if (cp!=NaN && cp<=max && cp>0)
	        {
		        window.location.href = baseurl + '&page=' + cp;
	        }
	        else
	        {
		        alert("您输入的页码错误");
		        $("GotoPage").value = "";
		        $("GotoPage").focus();
	        }
        }

		Loader.js(Dipan.SanGuo.Common.StaticsServer + "/@/JavaScripts/Prototype.js",true);
    },
    
    /**
     * 列表页面跳转
     * @param {baseurl} 页面
     * @param {max} 最大页码
     */
    StaticChangePage: function(baseurl,max)
    {
        var Loader = new Dipan.SanGuo.Common.Loader();
        
        Loader.onsuccess = function()
        {
            var cp = parseInt($("GotoPage").value);
	        if (cp!=NaN && cp<=max && cp>0)
	        {
		        window.location.href = baseurl + cp;
	        }
	        else
	        {
		        alert("您输入的页码错误");
		        $("GotoPage").value = "";
		        $("GotoPage").focus();
	        }
        }

		Loader.js(Dipan.SanGuo.Common.StaticsServer + "/@/JavaScripts/Prototype.js",true);
    },
    
    /**
     * 提交Form表单
     * @param {formname} Form名
     * @param {posturl} Post地址
     */
    FormPost: function()
    {
        this.Post = function(formname,posturl)
        {
             var postform = $(formname);
             
             var i = posturl.indexOf("?");
	         if(i >= 0)
	         {
		        posturl = posturl + "&" + Math.random();
	         }
	         else
	         {
		        posturl = posturl + "?" + Math.random();
	         }
	         
	         posturl = Dipan.SanGuo.Common.RequestServer + posturl;

             var self = this;
             new Ajax.Request(
                                 posturl==undefined?postform.action:posturl, 
                                 {
                                    asynchronous: true, 
                                    evalScripts: true,
                                    parameters: Form.serialize(postform),
                                    onComplete: function(resp)
                                    {
                                        self.onComplete(resp.responseText);
                                    }
                                  }
                                );
        }
        
        this.onComplete = function(resp){};
    },

	/**
     * 获取URL数据
     */
    RemoteData: function()
    {
        /**
         * GET获取URL数据
         * @param {url} 请求地址
         */
        this.Get = function(url,yn)
        {
             if (!yn) Dipan.SanGuo.Common.Loading("main","正在加载数据...");
        
             var i = url.indexOf("?");
	         if(i >= 0)
	         {
		        url = url + "&" + Math.random();
	         }
	         else
	         {
		        url = url + "?" + Math.random();
	         }
	         
	         url = Dipan.SanGuo.Common.RequestServer + url;
        
             var self = this;
             new Ajax.Request(
                                 url, 
                                 {
                                    method: "get",
                                    asynchronous: true, 
                                    evalScripts: true,
                                    onComplete: function(resp)
                                    {
                                        self.onComplete(resp.responseText);
                                        if (!yn) Dipan.SanGuo.Common.Loading("main");
                                    }
                                  }
                                );
        };

        /**
         * POST获取URL数据
         * @param {url} 请求地址
         * @param {params} 请求参数
         */
		this.Post = function(url, params,yn)
        {
             if (!yn) if(document.getElementById("main")) Dipan.SanGuo.Common.Loading("main","正在加载数据...");
        
             var i = url.indexOf("?");
	         if(i >= 0)
	         {
		        url = url + "&" + Math.random();
	         }
	         else
	         {
		        url = url + "?" + Math.random();
	         }
	         
	         url = Dipan.SanGuo.Common.RequestServer + url;
        
             var self = this;
             new Ajax.Request(
                                 url, 
                                 {
                                    method: "post",
                                    asynchronous: true, 
                                    evalScripts: true,
                                    parameters: params==undefined?"":params,
                                    onComplete: function(resp)
                                    {
                                        self.onComplete(resp.responseText);
                                        if (!yn) if(document.getElementById("main")) Dipan.SanGuo.Common.Loading("main");
                                    }
                                  }
                                );
        }
        
        this.onComplete = function(resp){};
    },
    
    //获取浏览器信息
    GetBrowser: function()
    {
        var __Agt = navigator.userAgent.toLowerCase();
        var __If  = /(firefox|netscape|opera).?[\/| ](.)\.([^;\)]+|[^\)]+\))$/.exec(__Agt);
        if(!__If) __If = /(msie) (.)\.[^;]+;/.exec(__Agt);
        var _Br=__If[1], _Ver=__If[2];
        return _Br+_Ver;
    },
    
    /**
     * 获取远程JSON数据
     * @param {divObj} 返回填充DIV容器
     */
    RemoteJsonObject: function(divObj,toObj,url)
    {
        this.divObj = divObj;
        this.toObj = toObj;
        this.url = url;
	    this.LoadJsonData(this);
    },
    
    /**
     * 加载远程JSON数据
     * @param {RJO} RJO对象
     */
    LoadJsonData: function(RJO)
    {
        var ifr = document.createElement('iframe');
	    ifr.id = "ifr_"+RJO.divObj.id;
	    ifr.width = "0";
	    ifr.height = "0";
	    document.body.appendChild(ifr);
	    ifr.src = RJO.divObj.href;
	    if(window.addEventListener)
	    {
		    ifr.addEventListener('load',function()
		    {
			        var o,ifrs = document.getElementsByTagName("iframe");
	                for (var i = 0; i < ifrs.length; i++)
	                { 
		                if (ifrs[i].id == 'ifr_' + RJO.divObj.id) 
		                {
					        o = frames[i].jsondata;
				        }	
			        }
	                if(o)
	                {
		                Dipan.SanGuo.Common.FixData(RJO.divObj.id,RJO.toObj.id, o);
		                document.body.removeChild(ifr);
	                }
	                else
	                {
	                    alert("匹配失败！");
	                }
		    }, false);
	    }
	    else
	    {
		    ifr.attachEvent('onload',function()
		    {
		        var o = frames['ifr_'+RJO.divObj.id].jsondata;
		        if(o)
		        {
			        Dipan.SanGuo.Common.FixData(RJO.divObj.id,RJO.toObj.id, o);
			        document.body.removeChild(ifr);
		        }
		        else
		        {
		            alert("匹配错误！");
		        }
		    });
	    }
    },
    /**
     * 获取模板
     * @param {tempId} 模版容器ID
     * @param {templetHTML} 填充DIV容器ID
     * @param {jDoc} JSON数据
     * @param {flag} 是否插入到body中的标志
     * @param {pos} 是否动态
     */
    FixData: function(templetHTML,divid,jDoc,flag,id)
    {
        //templetHTML = templetHTML.replace(/&lt;%/g,"<%").replace(/%&gt;/g,"%>").replace(/\[%/g,"<%").replace(/%\]/g,"%>").replace(/\{%/g,"<%").replace(/%\}/g,"%>").replace(/\<!--%/g,"<%").replace(/%-->/g,"%>");
        
        var Dialog = $(divid); 
        if(divid=='tab_show')
        {
            if(!$('_float'))
                return;
        }
        if(divid=='_float_tab')
        {
            if(!$('_float'))
                return;
        }
        if (!Dialog)
        {
            Dialog = document.createElement('DIV');
            Dialog.setAttribute("id", divid);
            document.body.appendChild(Dialog);
        }
        
        if (!flag)
		{
		    Dialog.className = "float_all";
		    Dialog.style.cssText = "position:absolute; z-index:1103754";
		}
		
		Dialog.innerHTML = TrimPath.processDOMTemplate(templetHTML, jDoc);
		
		/*if (divid == "_float_tab" && id*1 == -1)
		{
		    var currents = $("current_wood","current_iron","current_stone","current_food","current_monkey");
		    
		    var need_wood = $("need_wood").innerHTML*1;
		    var need_iron = $("need_iron").innerHTML*1;
		    var need_stone = $("need_stone").innerHTML*1;
		    var need_food = $("need_food").innerHTML*1;
		    var need_money = $("need_money").innerHTML*1;
		    
		    if (currents[0].innerHTML*1 < need_wood)
		    {
		        $("need_wood").style.color = "red";
		        $("need_wood").title = "木材不足,还差 " + (need_wood - currents[0].innerHTML*1);
		    }
		    if (currents[1].innerHTML*1 < need_iron)
		    {
		        $("need_iron").style.color = "red";
		        $("need_iron").title = "铁矿不足,还差 " + (need_iron - currents[1].innerHTML*1);
		    }
		    if (currents[2].innerHTML*1 < need_stone)
		    {
		        $("need_stone").style.color = "red";
		        $("need_stone").title = "石料不足,还差 " + (need_stone - currents[2].innerHTML*1);
		    }
		    if (currents[3].innerHTML*1 < need_food)
		    {
		        $("need_food").style.color = "red";
		        $("need_food").title = "粮食不足,还差 " + (need_food - currents[3].innerHTML*1);
		    }
		    if (currents[4].innerHTML*1 < need_money)
		    {
		        $("need_money").style.color = "red";
		        $("need_money").title = "铜钱不足,还差 " + (need_money - currents[4].innerHTML*1);
		   }
		}*/
    },

    /**
     * 填充数据
     * @param {templetHTML} 模板HTML
     * @param {jDoc} JSON数据
     * @param {jLevel} 模板jLevel
     * @param {childNode} 子节点
     */
    StartFix: function(templetHTML,jDoc,jLevel)
    {
        var stRegPrefix = "<%repeat_"+jLevel+"\\s*match=\"([^\"]+)\"[^%]*%>";
	    var stRegContent = "<%repeat_"+jLevel+"[^>]*%>((.|\\n)+)<%_repeat_"+jLevel+"%>";
	    var r_repeat_match = new RegExp(stRegPrefix);
	    var r_repeat_match_global = new RegExp(stRegPrefix,"g");
	    var r_repeat_content = new RegExp(stRegContent);
	    var r_repeat_match_next_level = new RegExp("<%repeat_"+(jLevel+1)+" match=\"([^\"]+)\"");
	    if (templetHTML.match(r_repeat_match) == null)
	    {
		    //alert("没有找到JSON节点<%repeat_"+(jLevel)+"%>");
		    return templetHTML;
	    }
	    var arPrefix = templetHTML.match(r_repeat_match_global);
	    var startPosition = 0;
	    
	    for (var i=0; i<arPrefix.length; i++)
	    {
		    var st = arPrefix[i];
		    var nodePath = st.replace(/^.*match=\"|\".*$/g,"");
		    startPosition = templetHTML.indexOf(st);
		    var endPosition = templetHTML.indexOf("<%_repeat_"+jLevel+"%>", startPosition);
		    var replaceContent = templetHTML.substring(startPosition, endPosition+13);
		    startPosition += st.length;
		    var repeatContent = templetHTML.substring(startPosition, endPosition); 
		    if(nodePath.indexOf('.') != -1)
		    {
			    var arjnode = nodePath.split('.')
			    var nodes = jDoc[arjnode[1]];
			    if(arjnode.length > 2)
			    {
				     nodes = nodes[i][arjnode[arjnode.length - 1]];
				}
		    }
		    else
		    {
			    var nodes = jDoc;
			}
		    var arContent = [];
		    if(!nodes)
		    {
			    alert("返回JSON数据子节点不存在")
		    }
		    else
		    {
			    if(typeof(nodes.length) == "undefined")
			    {
				    var z = 2;
				}
			    else
			    {
				    var z = nodes.length;
				}
			    for(var j = 0; j < z; j++)
			    {
				    var node = typeof(nodes.length) == "undefined"?nodes:nodes[j];	
				    var content = repeatContent;
				    if	(repeatContent.match(r_repeat_match_next_level) != null)
				    {
						content = Dipan.SanGuo.Common.StartFix(repeatContent,node,jLevel+1);
				    }		    
					    var s = content;
					    var l = content.match(/<%=[^%]+%>/g);
					    for(var k=0; k<l.length; k++)
					    {
						    if(l[k].indexOf('@fun=') > 0)
						    {
							    var func = l[k].replace(/^.*@fun=\"|\".*$/g,"");
							    var t = l[k].replace(/^<%=|@.*%>$/g,"");
							    if (t.indexOf(',') > 0)
							    {
							        var str1 = [];
							        var str2 = [];
							        var at = t.split(',');
							        for (var nI = 0; nI < at.length; nI ++)
							        {
							            str1[nI] = "str" + nI;
							            str2[nI] = node[at[nI]];
							        }
                                    var prefix = new Function(str1,"return "+func+"");
							        s = s.replace(/<%=[^%]+%>/,prefix(str2));
							    }
							    else
							    {
							        var prefix = new Function("str","return "+func+"");
							        s = s.replace(/<%=[^%]+%>/,prefix(node[t]));
							    }
						    }
						    else
						    {
							    var t = l[k].replace(/^<%=|%>$/g,"");
							    if(node[t] == undefined) node[t] = '';
							    s = s.replace(/<%=(\w+)%>/,node[t]);
						    }
					    }
					    arContent[j] = s;
				 }
			     templetHTML = templetHTML.replace(replaceContent, arContent.join(""));
			}
	    }
	    return templetHTML;
    },
    
    /**
     * 获取 DOM对象 WH
     * @param {parent} DOM对象
     */
    GetWindowScroll: function(parent) 
    {
        var T, L, W, H;
        parent = parent || document.body;  
        if (parent != document.body) 
        {
          T = parent.scrollTop;
          L = parent.scrollLeft;
          W = parent.scrollWidth;
          H = parent.scrollHeight;
        } 
        else {
          var w = window.top;
          with (w.document) {
            if (w.document.documentElement && documentElement.scrollTop) {
              T = documentElement.scrollTop;
              L = documentElement.scrollLeft;
            } else if (w.document.body) {
              T = body.scrollTop;
              L = body.scrollLeft;
            }
            if (w.innerWidth) {
              W = w.innerWidth;
              H = w.innerHeight;
            } else if (w.document.documentElement && documentElement.clientWidth) {
              W = documentElement.clientWidth;
              H = documentElement.clientHeight;
            } else {
              W = body.offsetWidth;
              H = body.offsetHeight
            }
          }
        }
        return { top: T, left: L, width: W, height: H };
    },
    
    /**
     * 公共模板
     */
    Template:
    {
        /**
         * 玩家信息浮层
         */


        InfoUser:['<div class="info_userleft">',
'<div class="gz yellow6"><a href="#" class="yellow_name" onclick="Dipan.SanGuo.Common.DelUser(); return false;">[删除帐号]</a></div>',
'<div class="pic"><img id="headimg" src="${Dipan.SanGuo.Common.StaticsServer}/@/Images/float/arm06.gif" width="60" height="45"/></div>',
'<div class="name"><a href="#" class="yellow_name" onclick="Dipan.SanGuo.Common.ShowKuoZhang(${peace_status}); return false;">[{if peace_status==1}和平{else}扩张{/if}状态]</a></div>',
'</div>',
'<div class="info_userright">',
'<ul>',
'{var arr=Dipan.SanGuo.Page.Today.guanfun(famous,credit)}',
'<li>主公：<font class="yellow6">${name}</font></li>',
'<li>联盟：<font class="yellow6">${ally_name}</font></li>',
'<li>元宝：<font class="yellow6">${bullion}</font> <a href="/interfaces/payselect.aspx" target="_blank" class="yellow_name">[充值]</a></li>',
'<li>点券：<font class="yellow6">${ticket}</font></li>',
//'<li>等级：<font class="yellow6">${level}级</font></li>',
'<li>声望：<font class="yellow6">${credit} <font class="pink">[${arr[2]}级]</font></font></li>',
'<li>威望：<font class="yellow6">${famous} <font class="pink">[${arr[1]}级]</font></font></li>',
'<li>官职：<font class="yellow6">${arr[0]}</font> <a href="#" class="yellow_name" onclick="Dipan.SanGuo.Page.Fun.today(); return false;">[金銮殿]</a></li>',
'</ul>',
'</div>']
    },
    /**
    *   更改玩家和平与扩张状态
    */
    ShowKuoZhang:function(type)
    {
        var Loader = new Dipan.SanGuo.Common.Loader();
        Loader.onsuccess = function()
        {
            Dipan.SanGuo.Build.KuoZhang.kuozhang(type);
        }
	    Loader.js(Dipan.SanGuo.Common.StaticsServer + "/@/JavaScripts/Build/kuozhang.js", true);
    },
    /**
     * 显示玩家信息浮层
     */
    ShowInfoUser: function()
    {
        var Loader = new Dipan.SanGuo.Common.Loader();
        
        Loader.onsuccess = function()
        {
            var o = $("InfoUser");
	        if (o.innerHTML == "")
            {
                var RemoteData = new Dipan.SanGuo.Common.RemoteData();
                RemoteData.Post("/GateWay/City.ashx?id=23", "");
                RemoteData.onComplete = function(resp)
                {
                    var JsonData = eval ('(' + resp + ')');
                    if (JsonData.ret * 1 == 0)
                    {
                        try
                        {
                            Dipan.SanGuo.Common.FixData(Dipan.SanGuo.Common.Template.InfoUser, "InfoUser", JsonData, true);
                            
                            var o = $("InfoUser");
                            if (o)
                            {
                                o.style.cssText = "position:absolute; z-index:1103754";
                                o.style.top = "50px";
                                o.style.left = "52px";
                                new Effect.Opacity('InfoUser', {duration:0.0, from:0.7, to:0.7});
                            }
                            
                            $("headimg").src = Dipan.SanGuo.Common.StaticsServer +  "/@/Images/headimg/" + JsonData.head_img + ".jpg";
                        }
                        catch (e)
                        {
                            //alert(e.message);
                        }
                    }
                    else
                    {
                        //返回不成功后到统一方法处理错误信息
                        Dipan.SanGuo.Common.ResultInfo(JsonData.ret);
                    }
                }
	        }
        }
        
        Loader.js(Dipan.SanGuo.Common.StaticsServer + "/@/JavaScripts/template.js", false);
        Loader.js(Dipan.SanGuo.Common.StaticsServer + "/@/JavaScripts/Page/today.js", true);
    },
    
    /**
     * 添加标记
     */
    AddBookMark: function(bname, blink)
    {
        var RemoteData = new Dipan.SanGuo.Common.RemoteData()
        RemoteData.Post("/GateWay/OPT.ashx?id=3", "bname=" + encodeURIComponent(bname) + "&blink=" + blink);
        RemoteData.onComplete = function(resp)
        {
            var JsonData = eval ('(' + resp + ')');
            if (JsonData.ret * 1 == 0)
            {
                alert("添加标记成功");
            }
            else
            {
                alert("添加标记失败");
            }
        }
    },
    
    /**
     * 隐藏信息浮层
     */
    HideInfoUser: function()
    {
	    var o = $("InfoUser");
	    if (o)
        {
            o.innerHTML = "";
	        o.style.display = "none";
	    }
    },
    
    /**
     * 删除帐号
     */
    DelUser: function()
    {
        var Loader = new Dipan.SanGuo.Common.Loader();
        
        Loader.onsuccess = function()
        {
            Dipan.SanGuo.DelUser.deluser();
        }
        
        Loader.js(Dipan.SanGuo.Common.StaticsServer + "/@/JavaScripts/Dipan.SanGuo.DelUser.js", true);
    },
    
    /**
     * 显示论坛信息
     */
    BBS: function()
    {
        var Loader = new Dipan.SanGuo.Common.Loader();
        
        Loader.onsuccess = function()
        {
            Dipan.SanGuo.BBS.bbs();
        }
        
        Loader.js(Dipan.SanGuo.Common.StaticsServer + "/@/JavaScripts/Dipan.SanGuo.BBS.js", true);
    },
    
    /**
     * 显示帮助信息
     */
    Help: function()
    {
        var Loader = new Dipan.SanGuo.Common.Loader();
        
        Loader.onsuccess = function()
        {
            Dipan.SanGuo.Help.help();
        }
        
        Loader.js(Dipan.SanGuo.Common.StaticsServer + "/@/JavaScripts/Dipan.SanGuo.Help.js", true);
    },
    
    /**
     * 显示传声浮层
     * @param {uid} 玩家编号
     */
    GetUserInfo: function(uid)
    {
        var Loader = new Dipan.SanGuo.Common.Loader();
        
        Loader.onsuccess = function()
        {
            Dipan.SanGuo.UserInfo.userinfo(uid);
        }
        
        Loader.js(Dipan.SanGuo.Common.StaticsServer + "/@/JavaScripts/Dipan.SanGuo.UserInfo.js", true);
    },
    
    /**
     * 显示讨伐任务浮层
     */
    BattleTask: function()
    {
        var Loader = new Dipan.SanGuo.Common.Loader();
        
        Loader.onsuccess = function()
        {
            Dipan.SanGuo.BattleTask.battletask();
        }
        
        Loader.js(Dipan.SanGuo.Common.StaticsServer + "/@/JavaScripts/Dipan.SanGuo.BattleTask.js", true);
    },
    
    /**
     * 显示传声浮层
     */
    ShowBroadcast: function()
    {
        var Loader = new Dipan.SanGuo.Common.Loader();
        
        Loader.onsuccess = function()
        {
            Dipan.SanGuo.Broadcast.broadcast();
        }
        
        Loader.js(Dipan.SanGuo.Common.StaticsServer + "/@/JavaScripts/Dipan.SanGuo.Broadcast.js", true);
    },
    
    /**
     * 初始化传声

     */
    InitBroadcast: function()
    {
        var Loader = new Dipan.SanGuo.Common.Loader();
        
        Loader.onsuccess = function()
        {
            Dipan.SanGuo.Broadcast.Initialize();
            Dipan.SanGuo.Common.GetFight();
            window.setInterval("Dipan.SanGuo.Common.F6()", 360000);
            window.setInterval("Dipan.SanGuo.Common.GetFight()", 360000);
            //window.setInterval("Dipan.SanGuo.Common._Resource()", 5000);//客户端刷新资源信息

        }
        
        Loader.js(Dipan.SanGuo.Common.StaticsServer + "/@/JavaScripts/Dipan.SanGuo.Broadcast.js", true);
    },
    /**
    *   资源客户端计算

    */
    _Resource:function()
    {
        //trace(parseInt($('output_wood').innerHTML*1/60));
        //trace($('current_wood').innerHTML*1+parseInt($('output_wood').innerHTML*1/60));
        //木头
        var ar=parseInt($('current_wood').innerHTML)+parseInt($('output_wood').innerHTML)/60;
        if(ar*1<0)ar=0;
        $('current_wood').innerTEXT=ar;
        
        //trace($('current_wood').innerHTML);
        //石头
        ar=ar=parseInt($('current_stone').innerHTML)+parseInt($('current_stone').innerHTML)/60;
        if(ar*1<0)ar=0;
        $('current_stone').innerTEXT=ar;
        //铁矿
        ar=ar=parseInt($('current_iron').innerHTML)+parseInt($('current_stone').innerHTML)/60;
        if(ar*1<0)ar=0;
        $('current_iron').innerTEXT=ar;
        //粮食
        ar=ar=parseInt($('current_food').innerHTML)+parseInt($('current_stone').innerHTML)/60;
        if(ar*1<0)ar=0;
        $('current_food').innerTEXT=ar;
    },
    /**
     * 地图初始化
     */
    MapInitialize: function()
    {
        var Loader = new Dipan.SanGuo.Common.Loader();
        
        Loader.onsuccess = function()
        {
            Dipan.SanGuo.Common.CityList();
            Dipan.SanGuo.Common.InitBroadcast();
            
        }
        Loader.js(Dipan.SanGuo.Common.StaticsServer + "/@/JavaScripts/Dipan.SanGuo.CityList.js", true);
    },
    
    /**
     * 城池初始化
     */
    CityInitialize: function()
    {
        var Loader = new Dipan.SanGuo.Common.Loader();
        
        Loader.onsuccess = function()
        {
            Dipan.SanGuo.Common.CityList();
            Dipan.SanGuo.Common.InitBroadcast();
            if(Dipan.SanGuo.Common.GetCookie('today')*1==1)
                Dipan.SanGuo.Page.Fun.today(1);
        }
        
        Loader.js(Dipan.SanGuo.Common.StaticsServer + "/@/JavaScripts/Dipan.SanGuo.City.js", false);
        Loader.js(Dipan.SanGuo.Common.StaticsServer + "/@/JavaScripts/Dipan.SanGuo.CityList.js", true);
    },
    
    /**
     * 休假模式
     */
    VacationInitialize: function()
    {
        var Loader = new Dipan.SanGuo.Common.Loader();
        
        Loader.onsuccess = function()
        {
            Dipan.SanGuo.Vacation.vacation();
        }
        
        Loader.js(Dipan.SanGuo.Common.StaticsServer + "/@/JavaScripts/Dipan.SanGuo.Vacation.js", true);
    },
    
    /**
     * 公共部分TAB切换
     * @param {id} TAB ID 1:资源,2:军队,3:城防
     */
    CityInfoTab: function(id)
    {
        Dipan.SanGuo.Build.Fun.HideItem();
        if (id == 1)
        {
            $("cityinfo_tab_1").innerHTML = '<span class="main_tab_btn_ing">资源</span>';
            $("cityinfo_tab_2").innerHTML = '<a href="#" class="flinkan" onclick="Dipan.SanGuo.Common.CityInfoTab(2); return false;">军队</a>';
            $("cityinfo_tab_3").innerHTML = '<a href="#" class="flinkan" onclick="Dipan.SanGuo.Common.CityInfoTab(3); return false;">城防</a>';
            Dipan.SanGuo.Common.F6();
        }
        else if (id == 2)
        {
            $("cityinfo_tab_1").innerHTML = '<a href="#" class="flinkan" onclick="Dipan.SanGuo.Common.CityInfoTab(1); return false;">资源</a>';
            $("cityinfo_tab_2").innerHTML = '<span class="main_tab_btn_ing">军队</span>';
            $("cityinfo_tab_3").innerHTML = '<a href="#" class="flinkan" onclick="Dipan.SanGuo.Common.CityInfoTab(3); return false;">城防</a>';
            Dipan.SanGuo.City.GetInfoTroops();
        }
        else if (id == 3)
        {
            $("cityinfo_tab_1").innerHTML = '<a href="#" class="flinkan" onclick="Dipan.SanGuo.Common.CityInfoTab(1); return false;">资源</a>';
            $("cityinfo_tab_2").innerHTML = '<a href="#" class="flinkan" onclick="Dipan.SanGuo.Common.CityInfoTab(2); return false;">军队</a>';
            $("cityinfo_tab_3").innerHTML = '<span class="main_tab_btn_ing">城防</span>';
            Dipan.SanGuo.City.GetInfoDefend();
        }
    },
    
    CityListData:null,
    
    /**
     * 城池列表
     * @param {yn} 是否第一次执行该函数
     */
    CityList: function(yn)
    {
        var Loader = new Dipan.SanGuo.Common.Loader();
        
        Loader.onsuccess = function()
        {
            var citylist = $("CityList");
            if  (!citylist)
            {
                
                var RemoteData = new Dipan.SanGuo.Common.RemoteData()
                RemoteData.Post("/GateWay/City.ashx?id=7","");
                
                RemoteData.onComplete = function(resp)
                {
                    var JsonData = eval('(' + resp + ')');
                    Dipan.SanGuo.Common.CityListData = JsonData;
                    if (JsonData.ret * 1 == 0)
                    {
                        try
                        {
                            var cid = Dipan.SanGuo.Common.GetCookie("cid");
                            var tid = Dipan.SanGuo.Common.GetCookie("tid");
                            if(tid * 1 < 0) cid = tid;
                            var id = Dipan.SanGuo.Common.GetCityListIndex(JsonData.infos,cid);
                            if (id == -1)
                            {   
                                id=0;
                            }
                            if($("__select___hidden"))
                                id=parseInt($("__select___hidden").value);
                            
                    
                            if (JsonData.infos[id][0] == 1||JsonData.infos[id][0] == 3||JsonData.infos[id][0] == 4)//是城池

                            {
                                if (tid*1 < 0)//是营寨

                                {
                                    Dipan.SanGuo.Common.SetCookie("tid", "0", {path:"/"});
                                }
                                Dipan.SanGuo.Common.SetCookie("cid", JsonData.infos[id][1], {path:"/"});
                                
                            }
                            else if (JsonData.infos[id][0] == 2)//是营寨

                            {
                                Dipan.SanGuo.Common.SetCookie("tid", JsonData.infos[id][1], {path:"/"});
                                Dipan.SanGuo.Common.SetCookie("cid", JsonData.infos[id][6], {path:"/"});
                            }
                            if (window.location.href.indexOf("/map/") == -1)
                            {
                                Dipan.SanGuo.Common.SetCookie("mid", JsonData.infos[id][3], {path:"/"});
                            }

                            Dipan.SanGuo.Common.SetCurrentCityTent(JsonData,id,yn);
                            if(yn)return;
                            var temp="",vardesc="";
                            for(i=0; i<JsonData.infos.length;i++)
                            {
                                if(id==i)
                                    vardesc=JsonData.infos[i][2];
                                temp +='{text:"'+JsonData.infos[i][2]+'",value:'+i+',type:'+JsonData.infos[i][0]+',x_pos:'+JsonData.infos[i][4]+',y_pos:'+JsonData.infos[i][5]+'},';
                            }
                            
                            temp=temp.substring(0,temp.length-1);
                            
                            var JsonData = '{floatid:"__select__",desc:"'+vardesc+'",value:'+id+',onchange:"Dipan.SanGuo.Common.CityList(1)",data:['+temp+']}';
                            Dipan.SanGuo.Common.GetCityList(JsonData);
                        }
                        catch (e)
                        {
                            //alert(e.message);
                        }
                    }
                    else
                    {
                        Dipan.SanGuo.Common.ResultInfo(JsonData.ret);
                    }
                }
            }
            else
            {
                Dipan.SanGuo.Common.CloseDialog('CityList');
            }
        }
        
        Loader.js(Dipan.SanGuo.Common.StaticsServer + "/@/JavaScripts/Dipan.SanGuo.Map.js", true);
    },
    
    /**
     * 获取对应编号城池对应的数组索引

     * @param {infos} 城池数组
     * @param {cid} 城池编号
     */
    GetCityListIndex: function(infos, cid)
    {
        for (i = 0; i < infos.length; i++)
        {
            if (infos[i][1]*1 == cid)
            {
                return i;
            }
        }
        
        return -1;
    },
    
    /**
     * 通知服务器改变当前所在城池

     * @param {data} 城池数组
     * @param {id} 城池对应的数组索引

     * @param {yn} 是否第一次执行该函数
     */
    SetCurrentCityTent: function(data,id,yn)
    {
        var RemoteData = new Dipan.SanGuo.Common.RemoteData();
        RemoteData.Post("/GateWay/City.ashx?id=50", "tid=" + Dipan.SanGuo.Common.GetCookie("tid"));
        RemoteData.onComplete = function(resp)
        {
            var JsonData = eval('(' + resp + ')');
            if (JsonData.ret * 1 == 0)
            {
                //重新获取城池信息
                if(yn==1)
                {
                    Dipan.SanGuo.Common.SetCookie("nid", "", {path:"/"});
                    if ($("map"))
                        window.location.href='/map';
                    else
                        window.location.href='/city';
                    return;
                }
                if ($("city_tent"))
                {
                    var nid = Dipan.SanGuo.Common.GetCookie("nid");
                    if (nid*1 > 0)//是NPC城池
                    {
                        var Loader = new Dipan.SanGuo.Common.Loader();
                        Loader.onsuccess = function()
                        {
                            Dipan.SanGuo.Npc.GetBuilding();
                            Dipan.SanGuo.Common.F6();
                            Dipan.SanGuo.City.GetBuildingOther();
                        }

		                Loader.js(Dipan.SanGuo.Common.StaticsServer + "/@/JavaScripts/Dipan.SanGuo.Npc.js",true);
                    }
                    else if (data.infos[id][0] == 1||data.infos[id][0] == 3||data.infos[id][0] == 4)//是城池

                    {
                        Dipan.SanGuo.City.GetBuilding();
                        Dipan.SanGuo.Common.F6();
                    }
                    else if (data.infos[id][0] == 2)//是营寨

                    {
                        var Loader = new Dipan.SanGuo.Common.Loader();
                        Loader.onsuccess = function()
                        {
                            Dipan.SanGuo.Tent.GetBuilding(data.infos[id][1]);
                            Dipan.SanGuo.Common.F6();
                            Dipan.SanGuo.City.GetBuildingOther();
                        }

		                Loader.js(Dipan.SanGuo.Common.StaticsServer + "/@/JavaScripts/Dipan.SanGuo.Tent.js",true);
                    }
                }
                if ($("map"))//如果是在地图页面重新加载地图数据
                {
                    Dipan.SanGuo.Map.Initialize();
                    Dipan.SanGuo.Common.F6();
                    Dipan.SanGuo.City.GetBuildingOther();
                }
            }
            else
            {
                //返回不成功后到统一方法处理错误信息
                Dipan.SanGuo.Common.ResultInfo(JsonData.ret);
            }
        }
    },
    
    /**
     * 获取DOM位置
     * @param {obj} 页面控件对象
     */
    GetPosition: function(obj)
    { 
        var top = 0,left = 0;
	    do 
	    {
		    top += obj.offsetTop;
		    left += obj.offsetLeft;
	    }
	    while (obj = obj.offsetParent);      

	    var arr = new Array();      
	    arr[0] = top;
	    arr[1] = left;       
	    return arr;
    },
    
    /**
     * 1970-1-1到当前时间的秒数
     */
    CurrentTime: function()
    {
        return Math.round(new Date().getTime() / 1000);
    },
    
    /**
     * 结束时间
     * @param {lefttime} 剩余时间
     */
    OverTime: function (lefttime)
    {
        var CurrentDate = new Date();
        var nHour = CurrentDate.getHours();
        var nMin = CurrentDate.getMinutes();
        var nSeconds = CurrentDate.getSeconds();
        var nCurrentTimeSeconds = nHour * 3600 + nMin * 60 + nSeconds;
        var aaa=nCurrentTimeSeconds + lefttime;
        if(aaa>86400)
        {
            for(var i=0;;i++)
            {
                aaa-=86400;
                if(aaa>0&&aaa<86400)
                {
                    if(i==0)
                        htmlstring="明天 ";
                    else if(i==1)
                        htmlstring="后天 ";
                    else
                        htmlstring=(i+1)+"天后 "; 
                    var atime = Dipan.SanGuo.Common.Seconds2Time(aaa).split(":");
                    htmlstring+=(atime[0] * 1) % 24 + ":" + atime[1] + ":" + atime[2] + "";
                    return htmlstring;
                }
            }
        }
        if(aaa>0)
        {
            htmlstring="今天 ";
            var atime = Dipan.SanGuo.Common.Seconds2Time(aaa).split(":");
            htmlstring+=(atime[0] * 1) % 24 + ":" + atime[1] + ":" + atime[2] + "";
            return htmlstring;
        }
        for(var i=0;;i++)
        {
            aaa+=86400;
            if(aaa>0)
            {
                if(i==0)
                    htmlstring="昨天 ";
                else if(i==1)
                    htmlstring="前天 ";
                else
                    htmlstring=i+"天前 "; 
                var atime = Dipan.SanGuo.Common.Seconds2Time(aaa).split(":");
                htmlstring+=(atime[0] * 1) % 24 + ":" + atime[1] + ":" + atime[2] + "";
                return htmlstring;
            }
        }
        return htmlstring;
//        trace('负:'+lefttime);
//        if(lefttime<0)
//            return this.FuOverTime(lefttime);
//        var CurrentDate = new Date();
//        var nHour = CurrentDate.getHours();
//        var nMin = CurrentDate.getMinutes();
//        var nSeconds = CurrentDate.getSeconds();
//        
//        var nCurrentTimeSeconds = nHour * 3600 + nMin * 60 + nSeconds;
//        
//        var atime = Dipan.SanGuo.Common.Seconds2Time(nCurrentTimeSeconds + lefttime).split(":");

//        if ((atime[0] * 1) < 24)
//        {
//            htmlstring = "今天 "+(atime[0] * 1 ) % 24 + ":" + atime[1]  +":" + atime[2] + "";
//        }
//        else if(Math.floor((atime[0] * 1) / 24) == 1)
//        {
//            htmlstring = "明天 "+(atime[0] * 1) % 24+":" + atime[1] + ":" + atime[2] + "";
//        }
//        else if(Math.floor((atime[0] * 1) / 24) == 2)
//        {
//            htmlstring = "后天 "+(atime[0] * 1) % 24 + ":" + atime[1] + ":" + atime[2] + "";
//        }
//        else
//        {
//            htmlstring = ""+Math.floor((atime[0] * 1) / 24) + "天后 " + (atime[0] * 1) % 24 + ":" + atime[1] + ":" + atime[2] + "";
//        }
//        
//        return htmlstring;
    },
    ArriveTime: function (lefttime,id)
    {
        var CurrentDate = new Date();
        var nHour = CurrentDate.getHours();
        var nMin = CurrentDate.getMinutes();
        var nSeconds = CurrentDate.getSeconds();
        
        var nCurrentTimeSeconds = nHour * 3600 + nMin * 60 + nSeconds;
        
        var atime = Dipan.SanGuo.Common.Seconds2Time(nCurrentTimeSeconds + lefttime).split(":");

        if ((atime[0] * 1) < 24)
        {
            htmlstring = "今天 <span id=\"arrive_time_"+id+"\">"+(atime[0] * 1 ) % 24 + ":" + atime[1]  +":" + atime[2] + "</span>";
        }
        else if(Math.floor((atime[0] * 1) / 24) == 1)
        {
            htmlstring = "明天 <span id=\"arrive_time_"+id+"\">"+(atime[0] * 1) % 24+":" + atime[1] + ":" + atime[2] + "</span>";
        }
        else if(Math.floor((atime[0] * 1) / 24) == 2)
        {
            htmlstring = "后天 <span id=\"arrive_time_"+id+"\">"+(atime[0] * 1) % 24 + ":" + atime[1] + ":" + atime[2] + "</span>";
        }
        else
        {
            htmlstring = ""+Math.floor((atime[0] * 1) / 24) + "天后 <span id=\"arrive_time_"+id+"\">" + (atime[0] * 1) % 24 + ":" + atime[1] + ":" + atime[2] + "</span>";
        }
        
        return htmlstring;
    },
    
    ArriveTime1: function (lefttime,id)
    {
        var CurrentDate = new Date();
        var nHour = CurrentDate.getHours();
        var nMin = CurrentDate.getMinutes();
        var nSeconds = CurrentDate.getSeconds();
        
        var nCurrentTimeSeconds = nHour * 3600 + nMin * 60 + nSeconds;
        
        var atime = Dipan.SanGuo.Common.Seconds2Time(nCurrentTimeSeconds + lefttime).split(":");
        
        if ((atime[0] * 1) < 24)
        {
            htmlstring = "今天 <span id=\"tab_time_"+id+"\">"+(atime[0] * 1 ) % 24 + ":" + atime[1]  +":" + atime[2] + "</span>";
        }
        else if(Math.floor((atime[0] * 1) / 24) == 1)
        {
            htmlstring = "明天 <span id=\"tab_time_"+id+"\">"+(atime[0] * 1) % 24+":" + atime[1] + ":" + atime[2] + "</span>";
        }
        else if(Math.floor((atime[0] * 1) / 24) == 2)
        {
            htmlstring = "后天 <span id=\"tab_time_"+id+"\">"+(atime[0] * 1) % 24 + ":" + atime[1] + ":" + atime[2] + "</span>";
        }
        else
        {
            htmlstring = ""+Math.floor((atime[0] * 1) / 24) + "天后 <span id=\"left_time_"+id+"\">" + (atime[0] * 1) % 24 + ":" + atime[1] + ":" + atime[2] + "</span>";
        }
        
        return htmlstring;
    },
    
    /**
     * 关闭对话框
     * @param {id} DOM ID
     */
    CloseDialog: function(id)
    {   
        var obj;
        if(id=='_plus')
        {
            obj=$('_plus');
            if (obj)obj.parentNode.removeChild(obj);
            return;
        }
        if(this.Timer1)window.clearTimeout(this.Timer1);
        if(this.Timer2)window.clearTimeout(this.Timer2);
        obj = $("selcct_float");
        if (obj)document.body.removeChild(obj);
        obj=$(id);
        if (obj)obj.parentNode.removeChild($(id));
        obj=$('_plus');
        if (obj)obj.parentNode.removeChild(obj);
    },
    
    /**
     * 时间到秒
     * @param {o} 时间
     */
    Time2Seconds: function(o)
    {
        arrTime = o.innerHTML.split(":");
        if ( arrTime.length > 2 )
        {
            if ( arrTime[2] == "0?" )
            {
                return -3;
            }
	        Seconds = arrTime[0] * 3600 + arrTime[1] * 60 + arrTime[2] * 1;
	        return Seconds;
	    }
	    else
	    {
	        return -3;
	    }
    },
    
    /**
     * 秒到时间转换
     * @param {s} 秒数
     */
    Seconds2Time: function(s)
    {
        if(s<0)s=s*-1;
        if(s >= 0)
	    {
		    HH = Math.floor(s/3600);
		    mm = Math.floor(s/60)%60;
		    ss = s%60;
		    time = HH + ":";
		    if(mm < 10)
		    {
			    time += "0";
		    }
		    time += mm + ":";
		    if(ss <10)
		    {
			   time += "0";
		    }
		    time += ss;
		    return time;
	    }
	    else if ( s <= 0 )
	    {
	        return "0:00:00";
	    }
    },
    
    /**
     * 秒到天数时间转换
     * @param {s} 秒数
     */
    Seconds2DayTime: function(s)
    {
        if (s >= 0)
        {
            var atime = Dipan.SanGuo.Common.Seconds2Time(s).split(":");
            var strReturnHtml = "";
            strReturnHtml += Dipan.SanGuo.Common.Seconds2Time(s);
           
            return strReturnHtml;
        }
        else if (s <= 0)
        {
            return "0:00:00";
        }
    },
    
    Timer1:null,
    Timer2:null,
    
    /**
     * 剩余时间倒记时
     * @param {gid} 建筑唯一ID
     */
    TimeSpan1: function(pid,gid,id,tab,cityId,yn)
    {
        var isu = 0;
        if(!yn)window.clearTimeout(this.Timer1);
        for (i = 0; ;i++)
		{
			var strid = "left_time_" + i;
			if ($(strid) != null)
			{
				var ntime = Dipan.SanGuo.Common.Time2Seconds($(strid))*1-1;
		        if(ntime==0 && isu == 0)
		        {
		            isu = 1;
		            window.clearTimeout(this.Timer2);
                    window.setTimeout('Dipan.SanGuo.City.Build('+pid+','+gid+','+id+','+tab+','+cityId+')', 1000);
                    Dipan.SanGuo.Common.F5();
		        }
		        var U = Dipan.SanGuo.Common.Seconds2Time(ntime);
		        $(strid).innerHTML = U;
			}
			else
			{
				if (i == 0)
			        return;
				break;
			}
		}
		if (isu == 0)
        {
            this.Timer1=window.setTimeout('Dipan.SanGuo.Common.TimeSpan1('+pid+','+gid+','+id+','+tab+','+cityId+',true)',1000);
        }
     },
     
    ArriveSpan: function()
    {
        var isu = 0;
        for (i = 0; ;i++)
		{
			var strid = "arrive_time_" + i;
			if ($(strid) != null)
			{
				var ntime = Dipan.SanGuo.Common.Time2Seconds($(strid))*1+1;
		        var U = Dipan.SanGuo.Common.Seconds2Time(ntime);
		        $(strid).innerHTML = U;
		        window.setTimeout('Dipan.SanGuo.Common.ArriveSpan()',1000);
			}
			else
			{
				if (i == 0)
			        return;
				break;
			}
        }
     },
     
    /**
     * 剩余时间倒记时
     * @param {fun} 倒记时结束后执行函数
     * @param {yn} 是否第一次执行函数

     */
    TimeSpan2: function(fun,yn)
    {
        var isu = 0;
        if(!yn)window.clearTimeout(this.Timer2);
        for (i = 0; ;i++)
		{
			var strid = "tab_time_" + i;
			if ($(strid) != null)
			{
				var ntime = Dipan.SanGuo.Common.Time2Seconds($(strid))*1-1;
		        if(ntime==0 && isu == 0)
		        {
		            isu = 1;
		            window.clearTimeout(this.Timer2);
			        window.setTimeout("Dipan.SanGuo."+fun, 1000);
		        }
		        var U = Dipan.SanGuo.Common.Seconds2Time(ntime);
		        $(strid).innerHTML = U;
			}
			else
			{
			    if (i == 0)
			        return;
				break;
			}
		}
		
		if (isu == 0)
        {
            this.Timer2 = window.setTimeout("Dipan.SanGuo.Common.TimeSpan2('"+fun+"',true)",1000);
        }
     },
     
    /**
     * 地块编号与坐标转换
     * @param {MapId} 地图编号
     */
    MapIdToPos:function(MapId)
    {
		var x = 0;
		var y = 0;

		x = (MapId - 1) % 1313 - 656;
		y = 656 - Math.floor((MapId - 1) / 1313);

		return x + "," + y;
    },
    
    /**
     * 坐标转换为地图编号
     * @param {x} 坐标x
     * @param {y} 坐标y
     */
    MapPosToId:function(x, y)
    {
		var nMapId = 0;
    
		nMapId = (656 + parseInt(x)) + (656 - parseInt(y)) * 1313 + 1;
        
        return nMapId;
    },
    
    /**
     * 下拉框控件
     * @param {JsonData} 填充数据
     */
    DropDown: function(JsonData)
    {
        Dipan.SanGuo.DropDown.Render(JsonData);
    },
    
    /**
     * 下拉框控件
     * @param {JsonData} 填充数据
     */
    DropDown1: function(JsonData)
    {
        Dipan.SanGuo.DropDown1.Render(JsonData);
    },
    
    /**
     * 下拉框控件
     * @param {JsonData} 填充数据
     */
    DropDown2: function(JsonData)
    {
        Dipan.SanGuo.DropDown2.Render(JsonData);
    },
    
    /**
     * 显示城池列表
     * @param {JsonData} 填充数据
     */
    GetCityList: function(JsonData)
    {
         Dipan.SanGuo.CityList.Render(JsonData);
    },

    /**
     * 返回升级条件字符串
     * @param {c} 返回条件值
     * @param   {yn}    有值表示科技升级使用
     */
    RetUp:function(c,yn)
    {
        var info = "升级条件：";
        if(yn!=null)info="研究条件：";
        if (c == 0) return info += "全部满足";
        
        var result = Dipan.SanGuo.Common.Condition(c);
        
        for (i = 0; i < result.length; i++)
        {
            if (result[i] == 1)
            {
                if(i==6&&yn!=null)
                    info +=  "<font class=\"red2\">正在研究</font>&nbsp;";
                else if(i==3&&yn!=null)
                    info +=  "<font class=\"red2\">研究队列已满</font>&nbsp;";
                else
                    info +=  "<font class=\"red2\">"+Dipan.SanGuo.Common.UpGradeInfo[i][0] + "</font>&nbsp;";
            }
        }
        
        return info;
    },
    
    /**
     * 升级条件
     * @param {c} 条件值

     */
    Condition: function(c)
    {
        var result = [];
        for (i = 0; i < 18; i++)
        {
            if ((c & Dipan.SanGuo.Common.UpGradeInfo[i][1]) > 0)
            {
                result[i] = 1;
            }
            else
            {
                result[i] = 0;
            }
        }
        
        return result;
    },
    
    /**
     * 升级条件
     */
    UpGradeInfo:
    [
        ["城池官府等级不够",0x1],
        ["城内大学殿等级不够",0x2],
        ["营寨内中军大帐等级不够",0x4],
        ["升级队列已满",0x8],
        ["仓库容量不足",0x10],
        ["营库容量不足",0x20],
        ["正在升级或拆除",0x40],
        ["前提条件1不足",0x100],
        ["前提条件2不足",0x200],
        ["粮食不足",0x400],
        ["木材不足",0x800],
        ["石料不足",0x1000],
        ["铁矿不足",0x2000],
        ["铜钱不足",0x4000],
        ["空闲人口不足",0x8000],
        ["相应经验点不足",0x10000],
        ["城池等级不足(请到官府扩建城池)",0x20000],
        ["已达到最高级别",0x40000]
        
    ],
    
    /**
     * 返回信息
     * @param {ret} 返回值
     */
    ResultInfo: function(ret, pid)
    {
        switch (ret * 1)
        {
            case -1:
                alert('连接服务器失败（请检测您的网络）。<br />最新公告请登陆论坛查看：<br />http://bbs1.dipan.com/');
                break;
            case 1 : 
                alert("操作失败，请稍后再试！");
                break;
            case 2 :
                alert("非法用户ID");
                break;
            case 3 :
                alert("非法地块编号");
                break;
            case 4 : 
                alert("非法城池编号");
                break;
            case 5 :
                alert("非法营寨编号");
                break;
            case 6 :
                alert("非法绿洲编号");
                break;
            case 7 : 
                {
                    if ($("_float") && pid != -1&&!$('map'))
                    {
                        Dipan.SanGuo.Common.CloseDialog("_float");
                        Dipan.SanGuo.Common.F5();
                    }
                    else
                        alert("尚未建造相应的功能建筑");
                }
                break;
            case 8 :
                alert("非法建筑位置ID");
                break;
            case 9 :
                alert("非法军械GID");
                break;
            case 10 : 
                alert("非法阵型类型GID");
                break;
            case 11 :
                alert("非法科技GID");
                break;
            case 12 :
                alert("非法的家族邀请注册码");
                break;
            case 13: 
                {
                    alert("战斗已结束");
                    window.location.href = "/city";
                }
                break;
            case 14 :
                alert("非法战场位置");
                break;
            case 15 :
                alert("字符串请大于0小于12(中文占两个字符)");
                break;
            case 16 :
                alert("封测激活码无效");
                break;
            case 17 :
                alert("该码无效");
                break;
            case 18 :
                alert("请原谅，本服城池已满，请选择其它服务器激活。");
                break;
            case 20 :
                alert("该人物不属于本城池或营寨");
                break;
            case 21 :
                alert("装备ID不存在");
                break;
            case 22 : 
                alert("用户帐号不存在");
                break;
            case 23 :
                alert("城池/营寨名不存在");
                break;
            case 24 :
                alert("联盟名称不存在");
                break;
            case 25 : 
                alert("名称已存在");
                break;
            case 26 :
                alert("交易挂单不存在");
                break;
            case 27 :
                alert("联盟编号不存在");
                break;
            case 28 :
                alert("宝箱不存在");
                break;
            case 29 :
                alert("没有匹配的钥匙");
                break;
            case 30 : 
                alert("用户元宝不足");
                break;
            case 31 : 
                alert("用户声望不够");
                break;
            case 32 :
                alert("资源不足");
                break;
            case 33 : 
                alert("用户铜钱不足");
                break;
            case 34 : 
                alert("城池内空闲人口不足");
                break;
            case 35 : 
                alert("当前城池没有可派的将领");
                break;
            case 36 : 
                alert("没有开采权");   
                break;
            case 37 : 
                alert("建筑已存在");   
                break;
            case 38 : 
                alert("技能点不足");
                break;
            case 39 : 
                alert("目的地被占用");
                break;
            case 40 : 
                alert("该人物忙");
                break;
            case 41 :
                alert("距离太远");
                break;
            case 42 :
                alert("城内军械数量不足");
                break;
            case 43 : 
                alert("将军等级限制");
                break;
            case 44 : 
                alert("暂时不能对该城寨继续使用同一计谋或道具");
                break;
            case 45 : 
                alert("用户点券数量不足");
                break;
            case 46 : 
                alert("不能频繁移动");
                break;
            case 47 : 
                alert("有军事动向，不能移动城池/营寨");
                break;
            case 48 : 
                alert("升级队列已满");
                break;
            case 49 : 
                alert("民心过低");
                break;
            case 50 : 
                alert("官府等级不够");
                break;
            case 51 : 
                alert("联盟贡献值不够");
                break;
            case 52 :
                alert("商队数量不足");
                break;
            case 53 :
                alert("新兵数量不足");
                break;
            case 54 :
                alert("不能频繁征收物资");
                break;
            case 55 :
                alert("不能频繁安抚百姓");
                break;
            case 56 :
                alert("聚贤楼等级不够");
                break;
            case 57 :
                alert("点将台等级不够");
                break;
            case 58 :
                alert("中军大帐等级不够");
                break;
            case 59:
                alert('属性点不足');
                break;
            case 60:
                alert('您需要先在人物->军事面板中设置相应军械');
                break;
            case 61:
                alert('正在寻访其他人物');
                break;
            case 62:
                alert('营寨使用计策瞒天过海，暂时无法移动');
                break;
            case 63:
                alert('超出城防设施容量上限');
                break;
           case 64:
                alert('人口已饱和，添丁失败');
                break;
           case 65:
                alert('比武已开始');
                break;
           case 66:
                alert('已有其它文官参加擂台');
                break;
           case 67:
                alert('已有其它武将参加擂台');
                break;
            case 68:
                alert('人物已经被别人寻访');
                break;
            case 69:
                alert('招募码错误');
                break;
            case 70:
                alert('人物已经被别人招募');
                break;
            case 71:
                alert('已有士兵，必须配置主军械');
                break;
            case 72:
                alert('出兵已超过90秒，无法撤回');
                break;
            case 73:
                alert('正在交易');
                break;
            case 74:
                alert('价格浮动超过限制');
                break;
            case 75:
                alert('请指定运送资源和铜钱数量');
                break;
            case 76:
                alert('赏金不够、赏赐失败');
                break;
            case 77:
                alert('当前修改属性不能大于其它两个属性之和');
                break;
            case 78:
                alert('冻结期内不能出兵');
                break;
            case 79:
                alert('正在完成任务');
                break;
            case 80:
                alert('新手任务全部完成');
                break;
            case 81:
                alert('驻扎营寨数量超过限制');
                break;
            case 82:
                alert('当前已有名士传闻，请到酒馆或客栈查看寻访。');
                break;
            case 83:
                alert('您的级别已超过激活码的级别，激活失败');
                break;
            case 84:
                alert('需先完成三个新手任务才能开启宝箱');
                break;
            case 85:
                alert('未找到任何传闻，提高自己的威望和声望可以增加机率(此次使用包打听,未扣除元宝)');
                break;
            case 86:
                alert('今日俸禄已领取');
                break;
            case 87:
                alert('无法给当前城池运送资源');
                break;
            case 88:
                alert('只能对城池使用');
                break;
           case 89:
                alert('城内有建筑、军事行动、增援部队无法遗弃');
                break;
           case 90:
                alert('没有相应道具，无法使用');
                break;
           case 91:
                alert('进攻/侦察军队在外移动，无法使用免战牌');
                break;
           case 92:
                alert('城池正处在免战期');
                break;
           case 93:
                alert('不满足休假前提条件');
                break;
            case 94:
                alert('正在迁都中');
                break;
            case 95:
                alert('官府正在升级或者拆除');
                break;
            case 96:
                alert('当前城池已经是都城');
                break;
            case 97:
                alert('新手保护期内无法出兵');
                break;
            case 98:
                alert('都城无法遗弃');
                break;
            case 99:
                alert('城池正在免战冻结期间');
                break;
            case 200:
                alert('您已经向对方宣战');
                break;
            case 201:
                alert('对方已经向您宣战');
                break;
            case 202:
                alert('威望不足');
                break;
            case 203:
                alert('该地域禁止建城或者扩城');
                break;
            case 204:
                alert('无法增援');
                break;
            case 205:
                alert('无法侦察');
                break;
            case 206:
                alert('没有开通城池该元宝功能或已过期');
                break;
            case 207:
                alert('城池等级不足');
                break;
            case 208:
                alert('七蛮部队不存在');
                break;
           case 209:
                alert('七蛮部队正在战斗，无法移动');
                break;
            case 210:
                alert('不能频繁使用包打听');
                break;
            case 211:
                alert('报名尚未开始');
                break;
            case 212:
                alert('对不起,您的奖励已领取过了');
                break;
            case 213:
                alert('军队数量超出限制');
                break;
            case 214:
                alert('武将体力不足，无法单挑');
                break;
            case 215:
                alert('没有带兵，无法出征');
                break;
            case 216:
                alert('每回合只能使用一次');
                break;
            case 217:
                alert('三级城才能使用另起炉灶');
                break;
            case 218:
                alert('竞投资格时间结束后加入联盟的无法报名参战');
                break;
            case 219:
                alert('每个玩家最多只能报名三支部队');
                break;
            case 220:
                alert('派遣参赛队伍数量已达到最大限制');
                break;
            case 221:
                alert('和平状态道具使用冻结期');
                break;
            case 222:
                alert('该道具无法叠加使用');
                break;
            case 100 : 
                window.location.href = "/blocked";
                break;
            case 101 :
                {
                    Dipan.SanGuo.Common.SetCookie("vacation_left", 7*24*3600, {path:"/"});
                    window.location.href = "/vacation";
                }
                break;
            case 102 : 
                alert("目标用户处于保护期或正在休假");
                break;
            case 103 : 
                {
                    Dipan.SanGuo.Common.SetCookie("delete_left", 3*24*3600, {path:"/"});
                    window.location.href = "/delaccount";
                }  
                break;
            case 1103754 : //重新登陆
                window.location.href = "/login";
                break;
            case 8599 : //帐号重复
                window.location.href = "http://pass.dipan.com/m.aspx?cn=UserLogout";
                break;
            default:
                alert("操作失败，请稍后再试！");
                break;
        }
    },
    
    /**
    * 战役作战状态定义
    */
    RetFightState:function(i)
    {
        switch (i)
        {
            case 0 :
                return "驻扎";
            case 1:
                return "等待进攻";
            case 2:
                return "正在进攻";
            case 3:
                return "等待防御";
            case 4:
                return "正在防御";
            case 5:
                return "撤出战斗";
        }
        return "";
    } ,
    
    /**
    * Dipan.SanGuo.Build.Barracks_ot中 显示军队动向
    * i 军队移动类型值
    * d 1=向本城移动 2=本城向其它城移动军队
    */
    RetMoveStateHtml:function(i,d)
    {
        var str="本城/寨";
        if(d==2)str="其它城/寨";
        switch (i)
        {
            case 1:
                return "攻击"+str;
            case 2:
                return "增援"+str;
            case 3:
                return "攻击"+str+"返回";
            case 4:
                return "增援"+str+"返回";
            case 5:
                return "调派派遣"+str;
            case 6:
                return "侦察";
            case 7:
                return "新建城池";
            case 8:
                return "新建营寨";
            case 9:
                return "侦察返回";
            case 10:
                return "寻访";
            case 11:
                return "返回";
        }
        return "";
    },  
    
    /**
    * 军队移动类型值定义
    */
    RetMoveState:function(i)
    {
        switch (i)
        {
            case 1:
                return "攻击";
            case 2:
                return "增援";
            case 3:
                return "攻击返回";
            case 4:
                return "增援返回";
            case 5:
                return "调派派遣";
            case 6:
                return "侦察";
            case 7:
                return "新建城池";
            case 8:
                return "新建营寨";
            case 9:
                return "侦察返回";
        }
        return "";
    },
    
     /**
     * 返回人物状态
     * @param {id} 状态码
     *        {yn} 1文官 2武官
     */
    ResultsStatus:function(id,yn)
    {
        switch(id)
        {
            case 0:
                return "正常";
                case 1:
                     return "<font class=\"red2\">重伤</font>";
                case 2:
                    return "疗伤";
                case 16:
                    return '<a href="#" class="username" onclick="Dipan.SanGuo.City.Build(-1,16,0,0,0);return false;">出征</a>';
                case 17:
                    return '<a href="#" class="username" onclick="Dipan.SanGuo.City.Build(-1,16,0,0,0);return false;">增援</a>';
                case 18:
                if(!yn)
                    return '比武';
                if(yn==1)
                    return '<a href="#" class="username" onclick="Dipan.SanGuo.City.Build(-1,9,0,2,0);return false;">比武</a>';
                else
                    return '<a href="#" class="username" onclick="Dipan.SanGuo.City.Build(-1,10,0,2,0);return false;">比武</a>';
                break;
                case 19:
                    return '<a href="#" class="username" onclick="alert(\'请到 客栈/酒馆->寻访 页面查看\');return false;">寻访</a>';
                case 20:
                    return '<a href="#" class="username" onclick="Dipan.SanGuo.City.Build(-1,16,0,0,0);return false;">侦察</a>';
                case 21:
                 return '<a href="#" class="username"" onclick="alert(\'请到该人物派遣目的地校场查看\');return false;">派遣</a>';
                case 22:
                    return '<a href="#" class="username" onclick="Dipan.SanGuo.City.Build(-1,16,0,0,0);return false;">建城</a>';
                case 23:
                    return '<a href="#" class="username" onclick="Dipan.SanGuo.City.Build(-1,16,0,6,0);return false;">建营寨</a>';
                case 24:
                    return "任务";
                case 25:
                    return "忙";
                case 26:
                    return "防御";
                case 27:
                    return '<a href="#" class="username" onclick="Dipan.SanGuo.City.Build(-1,16,0,0,0);return false;">练兵</a>';
                case 28:
                    return '联盟擂台';
                case 29:
                    return '增援驻扎';
                case 32:
                    return "返回";
        }
    },
    
    /**
     * 返回人物官职
     * @param {id} 状态码
     */
    ResultsJob:function(id)
    {
        if(id==0)return "赋闲";
        if(id==1)return "太守";
        if(id==2)return "军师";
        if(id==3)return "随军";
    },
    
    getBuildname:function(id)
    {
        return Dipan.SanGuo.Config.Buildings[id][0];
    },
    
    getBuildinfo:function(id)
    {
        return Dipan.SanGuo.Config.Buildings[id][1];
    },
    
    /**
     * 使用元宝功能
     * @param {type} 功能类型
     * @param {param1} 功能类型
     * @param {param2} 功能类型
     * @param {fun} 成功后执行函数
     * @param {paytype} 支付方式
     */
    UsePlusFunc: function(type, param1, param2, fun, paytype)
    {
        if(!paytype)paytype=1;
        var RemoteData = new Dipan.SanGuo.Common.RemoteData()
        RemoteData.Post("/GateWay/OPT.ashx?id=69","type=" + type + "&param1=" + param1 + "&param2=" + param2 + "&paytype=" + paytype);
        RemoteData.onComplete = function(resp)
        {
            var JsonData = eval('(' + resp + ')');
            if (JsonData.ret * 1 == 0)
            {
                try
                {
                    if(fun!=null)
                        eval(fun);
                    else
                    {
                        Dipan.SanGuo.Common.CloseDialog('_plus');
                        Dipan.SanGuo.PageTo.f5();
                        if(type==1||type==2)
                            Dipan.SanGuo.Common.F5();
                    }
                }
                catch (e)
                {
                    //alert(e.message);
                }
            }
            else
            {
                //返回不成功后到统一方法处理错误信息
                Dipan.SanGuo.Common.ResultInfo(JsonData.ret);
            }
        }
    },
    __TimeOut:function(json)
    {
        var max=0;
        for(var i=0;i<json.infos.length;i++)
        {
            if(json.infos[i][5]*1>0)
           {
               if(max==0)
                   max=json.infos[i][5]*1;
               else
                  max=Math.min(max,json.infos[i][5]*1);
           }
       }
       if(max>0)
           window.setTimeout('Dipan.SanGuo.Common.F5()', parseInt(max)*1000);
        return;
//        try
//        {
//            return;
//            //alert(duration);
//            var nowtime=Dipan.SanGuo.Common.CurrentTime();
//            window.setTimeout('Dipan.SanGuo.Common.F5()', parseInt(duration)*1000);
//            var temp= Dipan.SanGuo.Common.GetCookie("timeout");
//            if(temp=="")
//                temp="{list:[]}";
//            var str=temp.substring(temp.indexOf('[')+1,temp.lastIndexOf(']'));
//            str+=(parseInt(nowtime)+parseInt(duration))+",";
//            //alert(str);
//            str=str.substring(0,str.length-1);
//            str="{list:["+str+"]}";
//            Dipan.SanGuo.Common.SetCookie("timeout",str, {path:"/"});
//        }
//        catch(e)
//        {
//            //alert(e.message);
//            Dipan.SanGuo.Common.SetCookie("timeout","{list:[]}", {path:"/"});
//        }
    },
    /**
    *   执行建筑刷新
    */
    F5:function()
    {
        if($("map"))return;
        if(!$('city_tent'))return;
        if (Dipan.SanGuo.Common.GetCookie("tid")*1>=0)
            Dipan.SanGuo.City.GetBuilding();
        else
            Dipan.SanGuo.Tent.GetBuilding();
        var nid = Dipan.SanGuo.Common.GetCookie("nid");
        if (nid*1 > 0)//是NPC城池
        {
            var Loader = new Dipan.SanGuo.Common.Loader();
            Loader.onsuccess = function()
            {
                Dipan.SanGuo.Npc.GetBuilding();
            }

            Loader.js(Dipan.SanGuo.Common.StaticsServer + "/@/JavaScripts/Dipan.SanGuo.Npc.js",true);
        }
    },
    /**
    *   刷新城市信息，资源信息

    */
    F6:function()
    {
        if (Dipan.SanGuo.Common.GetCookie("tid")*1>=0)
        {
            Dipan.SanGuo.City.GetCityInfo();//刷城市基本信息

            Dipan.SanGuo.City.GetInfoResource();//刷资源
            return;
        }
        else
        {
            var Loader = new Dipan.SanGuo.Common.Loader();
            Loader.onsuccess = function()
            {
                Dipan.SanGuo.Tent.GetCityInfo();//刷城市基本信息

                Dipan.SanGuo.Tent.GetInfoResource();//刷资源
            }
            Loader.js(Dipan.SanGuo.Common.StaticsServer + "/@/JavaScripts/Dipan.SanGuo.Tent.js",true);
            return;
        }
        var nid = Dipan.SanGuo.Common.GetCookie("nid");
        if (nid*1 > 0)//是NPC城池
        {
            var Loader = new Dipan.SanGuo.Common.Loader();
            Loader.onsuccess = function()
            {
                Dipan.SanGuo.Npc.GetCityInfo();//刷城市基本信息

                Dipan.SanGuo.Npc.GetInfoNPCResource();//刷资源

            }
            Loader.js(Dipan.SanGuo.Common.StaticsServer + "/@/JavaScripts/Dipan.SanGuo.Npc.js",true);
        }               
    },
    F5TimeOut:function()
    {
        try
        {
            return;
            var nowtime=Dipan.SanGuo.Common.CurrentTime();
            var temp= Dipan.SanGuo.Common.GetCookie("timeout");
            if(temp=="")return;
            var json = eval('(' + temp + ')');
            var str="";
            for(i=0;i<json.list.length;i++)
            {
                if(json.list[i]*1-nowtime*1>0)//当前时间比储存时间小则重设定时器
                {
                    str+=json.list[i]+",";
                    window.setTimeout('Dipan.SanGuo.Common.F5()', (parseInt(json.list[i])-parseInt(nowtime))*1000);
                }
            }
            if(str.length>0)
                str=str.substring(0,str.length-1);
            str="{list:["+str+"]}";
            Dipan.SanGuo.Common.SetCookie("timeout",str, {path:"/"});
        }
        catch(e)
        {
            //alert(e.message);
            Dipan.SanGuo.Common.SetCookie("timeout","{list:[]}", {path:"/"});
        }
    },
    /**
     * 升级/拆除
     * @param {pid} 建筑位置ID
     * @param {gid} 建筑唯一ID
     * @param {cityid} 城池编号
     * @param {type} 1:升级,2:拆除
     */
    UpdateBuilding: function(pid,gid,cityid,type)
    {
        if (type == 2)
        {            
            var cf = confirm("确定要拆除？");
            cf.onClose = function()
            {
                if(cf.returnValue)
                {
                    var RemoteData = new Dipan.SanGuo.Common.RemoteData()
                    RemoteData.Post("/GateWay/OPT.ashx?id=65","pid=" + pid + "&gid="+gid+"&type=" + type + "&tid=" + cityid);
                    RemoteData.onComplete = function(resp)
                    {
                        var JsonData = eval('(' + resp + ')');
                        
                        if (JsonData.ret * 1 == 0)
                        {
                            try
                            {
                                //操作执行成功后再次获取数据显示建筑浮层id,tab,cityId
                                Dipan.SanGuo.City.Build(pid,gid,0,1,cityid);
                                if($("map"))return;
                                //Dipan.SanGuo.Common.__TimeOut(JsonData);
                                Dipan.SanGuo.Common.F5();
                                Dipan.SanGuo.Common.F6();
                            }
                            catch (e)
                            {
                                //alert(e.message);
                            }
                        }
                        else
                        {
                            //返回不成功后到统一方法处理错误信息
                            Dipan.SanGuo.Common.ResultInfo(JsonData.ret);
                        }
                    }
	            }
            }
        }
        else
        {
            var RemoteData = new Dipan.SanGuo.Common.RemoteData()
            RemoteData.Post("/GateWay/OPT.ashx?id=65","pid=" + pid + "&gid="+gid+"&type=" + type + "&tid=" + cityid);
            RemoteData.onComplete = function(resp)
            {
                var JsonData = eval('(' + resp + ')');
                
                if (JsonData.ret * 1 == 0)
                {
                    try
                    {
                        //操作执行成功后再次获取数据显示建筑浮层
                        Dipan.SanGuo.City.Build(pid,gid,0,1,cityid);
                        if($("map"))return;
                        Dipan.SanGuo.Common.F5();
                        Dipan.SanGuo.Common.F6();
                        //定时刷新
                        //Dipan.SanGuo.Common.__TimeOut(JsonData);
                    }
                    catch (e)
                    {
                        //alert(e.message);
                    }
                }
                else
                {
                    //返回不成功后到统一方法处理错误信息
                    Dipan.SanGuo.Common.ResultInfo(JsonData.ret);
                }
            }
        }
    },
    
    /**
     * 取消
     * @param {pid} 建筑位置ID
     * @param {gid} 建筑唯一ID
     * @param {cityid} 城池编号
     */
    CancelBuilding: function(pid,gid,cityid,fun)
    {        
        var cf = confirm("确定要取消？");
        cf.onClose = function()
        {
            if(cf.returnValue)
            {
                var RemoteData = new Dipan.SanGuo.Common.RemoteData()
                RemoteData.Post("/GateWay/OPT.ashx?id=10","pid=" + pid + "&tid=" +cityid);
                RemoteData.onComplete = function(resp)
                {
                    var JsonData = eval('(' + resp + ')');
                    
                    if (JsonData.ret * 1 == 0)
                    {
                        try
                        {
                              if(!fun)
                                Dipan.SanGuo.City.Build(pid,gid,0,1,cityid);
                              else
                                eval('Dipan.SanGuo.'+fun);
                                
                                if($("map"))return;
                                Dipan.SanGuo.Common.F5();
                                Dipan.SanGuo.Common.F6();
                        }
                        catch (e)
                        {
                            //alert(e.message);
                        }
                    }
                    else
                    {
                        //返回不成功后到统一方法处理错误信息
                        Dipan.SanGuo.Common.ResultInfo(JsonData.ret);
                    }
                }
	        }
        }
    },
    /**
    *   打开商城plus功能聚合页

    */
    plus:function()
    {
        //Dipan.SanGuo.PageTo.add('Dipan.SanGuo.Plus.Fun.store()');
        Dipan.SanGuo.Plus.Fun.store();
    },
    /**
     * 激活

     */
    Active: function()
    {
        if ($("loginname").value == "")
        {
            $("loginname").focus();
            alert("请输入登录名");
        }
        else if ($("state").value == "0")
        {
            $("state").focus();
            alert("请选择区域");
        }
        else
        {
            $("form").submit();
        }
    },
    
    /**
     * 登录
     */
    Login: function()
    {
        if ($("loginname").value == "")
        {
            $("loginname").focus();
            alert("请输入用户登录名");
        }
        else
        {
            $("form").submit();
        }
    },
    
    /**
     * 过滤
     * @param {str} 要过滤的字符串

     */
    ReplaceBadString: function(str)
    {
	    var badstr = new Array("法轮功","李洪志","大纪元","真善忍","新唐人","肉棍","淫靡","淫水","六四事件","迷药",
	    "迷昏药","窃听器","六合彩","买卖枪支","退党","三唑仑","麻醉药","麻醉乙醚","短信群发器","帝国之梦","毛一鲜",
	    "黎阳平","色情","对日强硬","出售枪支","迷药","摇头丸","西藏天葬","鬼村","军长发威","PK黑社会","恶搞晚会",
	    "枪决女犯","投毒杀人","强硬发言","出售假币","监听王","昏药","侦探设备","麻醉钢枪","反华","官商勾结",
	    "升达毕业证","手机复制","戴海静","自杀指南","自杀手册","张小平","佳静安定片","蒙汗药粉","古方迷香",
	    "强效失意药","迷奸药","透视眼镜","远程偷拍","自制手枪","子女任职名单","激情小电影","黄色小电影","色情小电影",
	    "天鹅之旅","盘古乐队","高校暴乱","高校群体事件","大学骚乱","高校骚乱","催情药","拍肩神药","春药","窃听器材",
	    "身份证生成器","枪决现场","出售手枪","麻醉枪","办理证件","办理文凭","疆独","藏独","高干子弟","高干子女",
	    "枪支弹药","血腥图片","反政府","禁书","无界浏览器","特码","反共","成人片","成人电影","换妻","三级片","胡锦涛",
	    "永久免费","全买网","催情春药","诚招代理商加盟","诚招代理","快速办理","少女迷情粉","长期销售","成人电影",
	    "激情电影","自拍写真","AV","sex","PP","迷魂药","蒙汗药","迷奸药","三唑仑","香港GHB迷幻液","催情春药","烈性春药",
	    "羟亚胺","假币","电表控","中国共产党","共产党","国民党","小日本","江泽民","朱镕基","李瑞环","温家宝","军火",
	    "手机监听器","汽车爆炸惨案","短信群发","窃听","复兴中华","特种部队","毛主席复活","老虎机","J8","毛","他妈的","傻B","图腾","moliyo","duowan", "多玩");

	    var reg;
	    var len = badstr.length;
	    for(var i=0;i<len;i++)
	    {
		    var rep = "";		
		    for(var k=0;k<badstr[i].length;k++)
			    rep += "*";
		    while(str.indexOf(badstr[i]) != -1)
		    {
			    str = str.replace(badstr[i],rep);
		    }
	    }
	    return str;
    },
    
    GoToLink: function(link)
    {
        Dipan.SanGuo.Common.SetCookie("link", link, {path:"/"});
        window.location.href = "/" + link;
    },
   
    /**
    *   升级聚合元宝功能
    */
    GetInFoAllPlus:function(temp,num)
    {
//        var RemoteData = new Dipan.SanGuo.Common.RemoteData();
//        RemoteData.Post("/GateWay/Common.ashx?id=8","");
//        RemoteData.onComplete = function(resp)
//        {
//            var JsonData;
//            JsonData = eval('(' + resp + ')');
//            if (JsonData.ret * 1 != 0)
//            {
//                 Dipan.SanGuo.Common.ResultInfo(JsonData.ret);
//                 temp+="</table>";
//                 if($('info_all'))
//                    $('info_all').innerHTML=temp;
//                 Dipan.SanGuo.Common.InfoTime();
//                 return;
//            }
//            for(var i=0;i<JsonData.list.length;i++)
//            {
//                if(JsonData.list[i][0]*1==3)
//                    {temp+='<tr><td height="22" class="tr2"><span class="tr2 yellow4"><span class="yellow1">建筑排程 剩余时间：</span><font id="font_time_'+num+'">'+Dipan.SanGuo.Common.Seconds2DayTime(JsonData.list[i][1])+'</font></span></td></tr>';num++;}
//                else if(JsonData.list[i][0]*1==4)
//                    {temp+='<tr><td height="22" class="tr2"><span class="tr2 yellow4"><span class="yellow1">2级绿洲开采权 剩余时间：</span><font id="font_time_'+num+'">'+Dipan.SanGuo.Common.Seconds2DayTime(JsonData.list[i][1])+'</font></span></td></tr>';num++;}
//                else if(JsonData.list[i][0]*1==5)
//                    {temp+='<tr><td height="22" class="tr2"><span class="tr2 yellow4"><span class="yellow1">3级绿洲开采权 剩余时间：</span><font id="font_time_'+num+'">'+Dipan.SanGuo.Common.Seconds2DayTime(JsonData.list[i][1])+'</font></span></td></tr>';num++;}
//                else if(JsonData.list[i][0]*1==6)
//                    {temp+='<tr><td height="22" class="tr2"><span class="tr2 yellow4"><span class="yellow1">4级绿洲开采权 剩余时间：</span><font id="font_time_'+num+'">'+Dipan.SanGuo.Common.Seconds2DayTime(JsonData.list[i][1])+'</font></span></td></tr>';num++;}
//                else if(JsonData.list[i][0]*1==7)
//                    {temp+='<tr><td height="22" class="tr2"><span class="tr2 yellow4"><span class="yellow1">5级绿洲开采权 剩余时间：</span><font id="font_time_'+num+'">'+Dipan.SanGuo.Common.Seconds2DayTime(JsonData.list[i][1])+'</font></span></td></tr>';num++;}
//                else if(JsonData.list[i][0]*1==15)
//                    {temp+='<tr><td height="22" class="tr2"><span class="tr2 yellow4"><span class="yellow1">人口上限加成5% 剩余时间：</span><font id="font_time_'+num+'">'+Dipan.SanGuo.Common.Seconds2DayTime(JsonData.list[i][1])+'</font></span></td></tr>';num++;}
//                else if(JsonData.list[i][0]*1==16)
//                    {temp+='<tr><td height="22" class="tr2"><span class="tr2 yellow4"><span class="yellow1">人口上限加成10% 剩余时间：</span><font id="font_time_'+num+'">'+Dipan.SanGuo.Common.Seconds2DayTime(JsonData.list[i][1])+'</font></span></td></tr>';num++;}
//                else if(JsonData.list[i][0]*1==17)
//                    {temp+='<tr><td height="22" class="tr2"><span class="tr2 yellow4"><span class="yellow1">人口上限加成20% 剩余时间：</span><font id="font_time_'+num+'">'+Dipan.SanGuo.Common.Seconds2DayTime(JsonData.list[i][1])+'</font></span></td></tr>';num++;}
//                else if(JsonData.list[i][0]*1==29)
//                    {temp+='<tr><td height="22" class="tr2"><span class="tr2 yellow4"><span class="yellow1">城池背景 剩余时间：</span><font id="font_time_'+num+'">'+Dipan.SanGuo.Common.Seconds2DayTime(JsonData.list[i][1])+'</font></span></td></tr>';num++;}
//                else if(JsonData.list[i][0]*1==24)
//                    {temp+='<tr><td height="22" class="tr2"><span class="tr2 yellow4"><span class="yellow1">城池外观 剩余时间：</span><font id="font_time_'+num+'">'+Dipan.SanGuo.Common.Seconds2DayTime(JsonData.list[i][1])+'</font></span></td></tr>';num++;}
//            }
            Dipan.SanGuo.Common.GetInFoAllJun(temp,num);
      // }
           
    },
     /**
    *   升级聚合显示军队动向信息
    */
    GetInFoAllJun:function(temp,num)
    {
        var tid=-1;
        if (Dipan.SanGuo.Common.GetCookie("tid")*1<0)
            tid=Dipan.SanGuo.Common.GetCookie("tid")
        var nid = Dipan.SanGuo.Common.GetCookie("nid");
        if (nid*1 > 0)//是NPC城池
            return;
        var RemoteData = new Dipan.SanGuo.Common.RemoteData()
        RemoteData.Post("/GateWay/City.ashx?id=37","ttid="+tid);
        RemoteData.onComplete = function(resp)
        {
            var JsonData = eval('(' + resp + ')');
            if (JsonData.ret * 1 == 0)
            {
                try
                {
                   var p=JsonData.list[0][4];

                   for(var i=0;i<p.length;i++)
                   {
                        temp+="<tr>";
                        temp+='<td height="22" class="tr2"><span class="tr2 yellow4"><span class="yellow1">'+Dipan.SanGuo.Config.Buildings[p[i][1]][0]+'：';
                        if(p[i][3]*1==1)
                            temp+='升级';
                        else
                            temp+='拆除';
                        temp+='中（'+p[i][2]+'<img src="'+Dipan.SanGuo.Common.StaticsServer +'/@/Images/float/kjian.gif" width="20" height="12" /> ';
                        if(p[i][3]*1==1)
                            temp+=(p[i][2]*1+1);
                        else
                            temp+=(p[i][2]*1-1);;
                        temp+='）</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;剩余：<font id="font_time_'+num+'">'+Dipan.SanGuo.Common.Seconds2DayTime(p[i][4])+'</font></span></td>';
                        temp+='</tr>';
                        num++;
                   }
                   p=JsonData.tech;
                   if(p[0]>0)
                   {
                        temp+="<tr>";
                        temp+='<td height="22" class="tr2"><span class="tr2 yellow4"><span class="yellow1">'+Dipan.SanGuo.Config.academy[29-p[0]][2]+'：';
                        temp+='研究（'+p[1]+'<img src="'+Dipan.SanGuo.Common.StaticsServer +'/@/Images/float/kjian.gif" width="20" height="12" /> '+(p[1]*1+1)+'）</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;剩余：<font id="font_time_'+num+'">'+Dipan.SanGuo.Common.Seconds2DayTime(p[2])+'</font></span></td>';
                        temp+='</tr>';
                        num++;
                   }
                   
                   p=JsonData.list[0][5]; //练兵
                   for(var i=0;i<p.length;i++)
                   {
                        temp+="<tr>";
                        temp+='<td height="22" class="tr2"><span class="tr2 yellow4"><span class="yellow1">练兵：'+p[i][1]+'：';
                        temp+='（当前士气：'+p[i][2]+'）</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;剩余：<font id="font_time_'+num+'">'+Dipan.SanGuo.Common.Seconds2DayTime(p[i][3])+'</font></span></td>';
                        temp+='</tr>';
                        num++;
                   }
                   
                   p=JsonData.list[0][6]; //营寨冷结时间
                   for(var i=0;i<p.length;i++)
                   {
                        temp+="<tr>";
                        temp+='<td height="22" class="tr2"><span class="tr2 yellow4"><span class="yellow1">';
                        if(p[i][0]*1>0)
                            temp+='城池';
                        else
                            temp+='营寨';
                        temp+='：'+p[i][1]+'：';
                        temp+='</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;冻结剩余时间：<font id="font_time_'+num+'">'+Dipan.SanGuo.Common.Seconds2DayTime(p[i][3])+'</font></span></td>';
                        temp+='</tr>';
                        num++;
                   }
                   p=JsonData.task;//讨伐
                   if(p[2]>0)
                   {
                        temp+="<tr>";
                        temp+='<td height="22" class="tr2"><span class="tr2 yellow4"><span class="yellow1">讨伐：';
                        temp+=p[1]+'  ';
                        
                        if(p[2]*1==1)
                            temp+='正在前往';
                        else if(p[2]*1==2)
                            temp+='正在战斗';
                        else if(p[2]*1==3)
                            temp+='正在返回';

                        temp+='</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;剩余：<font id="font_time_'+num+'">'+Dipan.SanGuo.Common.Seconds2DayTime(p[3])+'</font></span></td>';
                        temp+='</tr>';
                        num++;
                   }
                   
                   p=JsonData.list[0][7]; //免战
                   if(p!=-1)
                   {
                        temp+="<tr>";
                        temp+='<td height="22" class="tr2"><span class="tr2 yellow4"><span class="yellow1">';
                        temp+='免战剩余时间：</span><font id="font_time_'+num+'">'+Dipan.SanGuo.Common.Seconds2DayTime(p)+'</font></span></td>';
                        temp+='</tr>';
                        num++;
                   }
                   
                   if(num==0)
                   {
                        temp+="<tr>";
                        temp+='<td height="22" class="tr2"><span class="tr2 yellow4"><span class="yellow1">当前没有正在进行的建筑、科技、练兵任务或营寨冻结时间</span></td>';
                        temp+='</tr>';
                   }
                   temp+="</table>";
                    if($('info_all'))
                        $('info_all').innerHTML=temp;
                   
                }
                catch (e)
                {
                    //alert(e.message);
                }
            }
            else
            {
                Dipan.SanGuo.Common.ResultInfo(JsonData.ret);
            }
        }
    },
    GetInfoAll:function()
    {
        if($("map"))return;
        if(!$('city_tent'))return;
        var cid = Dipan.SanGuo.Common.GetCookie("cid");
        var tid = Dipan.SanGuo.Common.GetCookie("tid");
        if(tid * 1 < 0) cid = tid;
        var RemoteData = new Dipan.SanGuo.Common.RemoteData();
        RemoteData.Post("/GateWay/Common.ashx?id=41","lCityCampID="+cid);
        RemoteData.onComplete = function(resp)
        {
            var JsonData;
            JsonData = eval('(' + resp + ')');
            if (JsonData.ret * 1 != 0)
            {
                 Dipan.SanGuo.Common.ResultInfo(JsonData.ret);
                 temp+="</table>";
                 if($('info_all'))
                    $('info_all').innerHTML=temp;
                 Dipan.SanGuo.Common.InfoTime();
                 return;
            }
            
            var temp='<table width="99%" border="0" align="center" cellpadding="0" cellspacing="3">';
            var num=0;
            if(JsonData.infos[0][2][0]*1>0)
                {temp+='<tr><td height="22" class="tr2"><span class="tr2 yellow4"><span class="yellow1">来犯的军队 '+JsonData.infos[0][2][0]+' 支 最早到达时间还剩：</span><font id="font_time_'+num+'">'+Dipan.SanGuo.Common.Seconds2DayTime(JsonData.infos[0][2][1])+'</font></span></td></tr>';num++;}
            else if(JsonData.infos[0][3][0]*1>0)
                {temp+='<tr><td height="22" class="tr2"><span class="tr2 yellow4"><span class="yellow1">增援过来军队 '+JsonData.infos[0][3][0]+' 支 最早到达时间还剩：</span><font id="font_time_'+num+'">'+Dipan.SanGuo.Common.Seconds2DayTime(JsonData.infos[0][3][1])+'</font></span></td></tr>';num++;}
            else if(JsonData.infos[0][4][0]*1>0)
                {temp+='<tr><td height="22" class="tr2"><span class="tr2 yellow4"><span class="yellow1">出征的军队 '+JsonData.infos[0][4][0]+' 支 最早到达时间还剩：</span><font id="font_time_'+num+'">'+Dipan.SanGuo.Common.Seconds2DayTime(JsonData.infos[0][4][1])+'</font></span></td></tr>';num++;}
            else if(JsonData.infos[0][5][0]*1>0)
                {temp+='<tr><td height="22" class="tr2"><span class="tr2 yellow4"><span class="yellow1">增援出去军队 '+JsonData.infos[0][5][0]+' 支 最早到达时间还剩：</span><font id="font_time_'+num+'">'+Dipan.SanGuo.Common.Seconds2DayTime(JsonData.infos[0][5][1])+'</font></span></td></tr>';num++;}
            else if(JsonData.infos[0][6][0]*1>0)
                {temp+='<tr><td height="22" class="tr2"><span class="tr2 yellow4"><span class="yellow1">返回的军队 '+JsonData.infos[0][6][0]+' 支 最早到达时间还剩：</span><font id="font_time_'+num+'">'+Dipan.SanGuo.Common.Seconds2DayTime(JsonData.infos[0][6][1])+'</font></span></td></tr>';num++;}
            else if(JsonData.infos[0][7][0]*1>0)
                {temp+='<tr><td height="22" class="tr2"><span class="tr2 yellow4"><span class="yellow1">建立新城/营寨 '+JsonData.infos[0][7][0]+' 支 最早到达时间还剩：</span><font id="font_time_'+num+'">'+Dipan.SanGuo.Common.Seconds2DayTime(JsonData.infos[0][7][1])+'</font></span></td></tr>';num++;}
            
            Dipan.SanGuo.Common.GetInFoAllJun(temp,num);
            Dipan.SanGuo.Common.InfoTime();
         }
    },
    Timer3:null,
    InfoTime: function()
    {
        var isu = 0;
        for (i = 0; ;i++)
		{
			var strid = "font_time_" + i;
			if ($(strid) != null)
			{
				var ntime = Dipan.SanGuo.Common.Time2Seconds($(strid))*1-1;
		        if(ntime==0 && isu == 0)
		        {
		            isu = 1;
		            window.clearTimeout(this.Timer3);
			        window.setTimeout("Dipan.SanGuo.Common.GetInfoAll()", 1000);
		        }
		        var U = Dipan.SanGuo.Common.Seconds2Time(ntime);
		        $(strid).innerHTML = U;
			}
			else
			{
			    if (i == 0)
			        return;
				break;
			}
		}
		if (isu == 0)
        {
            window.clearTimeout(this.Timer3);
            this.Timer3 = window.setTimeout("Dipan.SanGuo.Common.InfoTime()",1000);
        }
     },
    /**
    *   开关升级聚合信息

    */
    InitInfoAllOpen:function()
    {   
        if(!$('info_all'))return;
        if($('info_all').style.display=="")
        {   
            $('info_all').parentNode.style.display="none";
            $('info_all').parentNode.parentNode.childNodes[0].style.display="none";
            Dipan.SanGuo.Common.SetCookie("infoall", "0", {path:"/"});
            $('info_all').style.display="none";
            $('infoxx1').src=Dipan.SanGuo.Common.StaticsServer + "/@/Images/float/inform03.gif";
            $('infoxx1').onmouseover=function()
            {
                $('infoxx1').src=Dipan.SanGuo.Common.StaticsServer + '/@/Images/float/inform03a.gif';
            }
            $('infoxx1').onmouseout=function()
            {
                $('infoxx1').src=Dipan.SanGuo.Common.StaticsServer + '/@/Images/float/inform03.gif';
            }
        }
        else
        {
            Dipan.SanGuo.Common.SetCookie("infoall", "1", {path:"/"});
            $('info_all').parentNode.style.display="";
            $('info_all').parentNode.parentNode.childNodes[0].style.display="";
            $('info_all').style.display="";
            
            $('infoxx1').src=Dipan.SanGuo.Common.StaticsServer + "/@/Images/float/inform04.gif";
            $('infoxx1').onmouseover=function()
            {
                $('infoxx1').src=Dipan.SanGuo.Common.StaticsServer + '/@/Images/float/inform04a.gif';
            }
            $('infoxx1').onmouseout=function()
            {
                $('infoxx1').src=Dipan.SanGuo.Common.StaticsServer + '/@/Images/float/inform04.gif';
            }
            this.GetInfoAll();
        }
    },
    /**
    *   显示升级聚合信息
    */
    InitInfoAll:function()
    {
        if(Dipan.SanGuo.Common.GetCookie("infoall")=="")
        {
            $('info_all').style.display="none";
            this.InitInfoAllOpen();
            return;
        }
        if(Dipan.SanGuo.Common.GetCookie("infoall")*1==1)
        {
            $('info_all').style.display="none";
            this.InitInfoAllOpen();
        }
        else
        {
            $('info_all').style.display="";
            this.InitInfoAllOpen();
        }
    },
    /**
    *   浮出关闭按钮
    *   yn==1 内政和军事  
    */
    InitClose:function(yn)
    {
        var imgsrc="close_a.gif";
        if(yn==null)
            imgsrc="float/f_11.gif";
        var urlhref="/city";
        var url=window.location.href;
        url=url.substring(window.location.href.lastIndexOf("/"));
        url=url.replace('#','');
        if(url=="/map")urlhref="/map";
        
        var temp=['<a href="${href}"><img src="${Dipan.SanGuo.Common.StaticsServer}/@/Images/${src}" /></a>'];
        Dipan.SanGuo.Common.FixData(temp, "__close", {href:urlhref,src:imgsrc}, true);
        var d=$('__close');
        d.style.cssText = "position:absolute; z-index:1103753";
        d.style.display = "";
        var fenb=0;
        var obj = Dipan.SanGuo.Common.GetWindowScroll(false);
        if(obj.width>1024)
            fenb=(obj.width-1024)/2 + 12;
        if(yn==1)
        {
            d.style.top = 63+'px';
            d.style.left =(fenb+ 924)+'px';
        }
        else
        {
            d.style.top = 65+'px';
            d.style.left =(fenb+ 910)+'px';
        }
    },
    InitLink: function()
    {
       var url=window.location.href;
       url=url.substring(window.location.href.lastIndexOf("/"));
       url=url.replace('#','');
       if(url.indexOf('?')>0)
            url=url.substring(0,url.indexOf('?'))
       if(url!="/city"&&url!="/map")
                this.InitClose();
       if(url=="/city")
            this.InitInfoAll();
        var link = Dipan.SanGuo.Common.GetCookie("link");
        
        if (link != "")
        {
            switch(link)
            {
                case "city":
                    {
                        MM_swapImage('1103754_city','','/@/Images/shallow/top_cc2.gif',1);
                        $("1103754_city").onmouseout = function()
                        {return false;}
                    }
                    break;
                case "map":
                    {
                        MM_swapImage('1103754_map','','/@/Images/shallow/top_map2.gif',1);
                        $("1103754_map").onmouseout = function()
                        {return false;}
                    }
                    break;
                case "alliance":
                    {
                        MM_swapImage('1103754_alliance','','/@/Images/shallow/top_lm2.gif',1);
                        $("1103754_alliance").onmouseout = function()
                        {return false;}
                    }
                    break;
                case "message":
                    {
                        MM_swapImage('1103754_message','','/@/Images/shallow/top_xx2.gif',1);
                        $("1103754_message").onmouseout = function()
                        {return false;}
                    }
                    break;
                case "report":
                    {
                        MM_swapImage('1103754_report','','/@/Images/shallow/top_bg2.gif',1);
                        $("1103754_report").onmouseout = function()
                        {return false;}
                    }
                    break;
                case "task":
                    {
                        MM_swapImage('1103754_task','','/@/Images/shallow/top_rw2.gif',1);
                        $("1103754_task").onmouseout = function()
                        {return false;}
                    }
                    break;
            }
        }
        else
        {
            MM_swapImage('1103754_city','','/@/Images/shallow/top_cc2.gif',1);
            $("1103754_city").onmouseout = function()
            {return false;}
        }
    },
    GetFight:function()
    {
        var RemoteData = new Dipan.SanGuo.Common.RemoteData();
        RemoteData.Post("/GateWay/Common.ashx?id=46","");
        RemoteData.onComplete = function(resp)
        {
            if(!$('user_notify_info'))return;
            $('user_notify_info').value=resp;
            Dipan.SanGuo.Common.InitFight();
        }
    },
    InitFight:function()
    {
        if($('user_notify_info')==null)
            return;
        if($('user_notify_info').value=="")
            return;
       if($('1103754_message')==null)
            return;
        var js_user_notify_info=eval('(' +$('user_notify_info').value + ')') ;
        if(js_user_notify_info.ret * 1 != 0)
            return;
        if(js_user_notify_info.newreport * 1 != 0)
             $('1103754_report').src='/@/Images/shallow/top_bg3.gif';
        if(js_user_notify_info.newmsg * 1 != 0)
            $('1103754_message').src='/@/Images/shallow/top_xx3.gif';
         if(js_user_notify_info.war * 1 == 1)
         {
             $('war_img').src='/@/Images/shallow/s_06a.gif';
             $('war_img').onclick=function()
             {
                Dipan.SanGuo.Page.Fun.alarm();
//				if (Dipan.SanGuo.Common.GetCookie("tid")*1 >= 0 )
//					Dipan.SanGuo.City.Build(-1,16,0,1,0);
//				else
//					Dipan.SanGuo.City.Build(-1,19,0,1,0);
               return false;
              }
         }
         else if(js_user_notify_info.war * 1 == 2)
         {
             $('war_img').src='/@/Images/shallow/s_59.gif';
             $('war_img').onclick=function()
             {
                Dipan.SanGuo.Page.Fun.alarm();
               return false;
              }
         }
    }
};

//<%=JsForController %>

//function KillErrors()
//{
//    return true;
//}
//window.onerror = KillErrors;

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//var nn6=$&&!document.all; //判断IE还是FF
function __onkeydown(e)   
 {
    var obj=!document.all?e:event;
    if (obj.target) targ = obj.target;
    else if (obj.srcElement) targ = obj.srcElement;
    
    if(obj.ctrlKey&&obj.keyCode==71)
    {
        Dipan.SanGuo.Broadcast._open();
        return false;
    }
    else if(obj.keyCode==9)
    {
        if(targ.tagName.toLowerCase()=="input"&&targ.id!="message")
	        return true;
        if($('_chat_show').style.display=='')
        {
            Dipan.SanGuo.Common.SetCookie('blindex',1);
            $('_chat_show').style.display='none';
            $('_res_show').style.display='';
        }
        else
        {
            Dipan.SanGuo.Common.SetCookie('blindex',2);
            $('_chat_show').style.display='';
            $('_res_show').style.display='none';
        }
        return false;
    }
    if(targ.tagName.toLowerCase()=="input")
	        return true;
    switch(obj.keyCode)
    {
        case 112:
            window.location.href='/city';
            return false;
        //case 113:
        //    window.location.href='/map';
        //    return false;
        case 114:
            window.location.href='/message';
            return false;
        case 115:
            window.location.href='/report';
            return false;
    }
    
    if(obj.shiftKey&&obj.keyCode==123)
    {
        var RemoteData = new Dipan.SanGuo.Common.RemoteData();
        RemoteData.Post("/GateWay/Common.ashx?id=51","");
        RemoteData.onComplete = function(resp)
        {
            JsonData = eval('(' + resp + ')');
            if (JsonData.ret * 1 == -1)
                return true;
            alert(JsonData.xx +"<br />"+Dipan.SanGuo.Common.Seconds2DayTime(Dipan.SanGuo.Common.CurrentTime()*1-Dipan.SanGuo.Common.GetCookie('system')*1));
        }
        return false;
    }
    else if(obj.shiftKey&&obj.keyCode==49)//内政
    {
        Dipan.SanGuo.Page.Fun.manager();
        return false;
    }
    else if(obj.shiftKey&&obj.keyCode==50)//军事
    {
        Dipan.SanGuo.Page.Fun.troops();
        return false;
    }
    else if(obj.shiftKey&&obj.keyCode==51)//充值

    {
        alert('充值');
        return false;
    }
    else if(obj.shiftKey&&obj.keyCode==52)//商城
    {
        Dipan.SanGuo.Common.plus();
        return false;
    }
    //else if(obj.keyCode==117)//F6 查看存有信息
    //{
        //Dipan.SanGuo.PageTo.show();
	   // return false;
    //}
	else if(obj.keyCode==27)
	{
	    //Dipan.SanGuo.PageTo.show();
	   // return;
	    var obj=$('_alert');
	    if (obj)
        {
            obj.parentNode.removeChild(obj);
            return false;
        }
	    obj=$('_plus');
        if (obj)
        {
            obj.parentNode.removeChild(obj);
            return false;
        }
		Dipan.SanGuo.Common.CloseDialog('_float');
		return false;
	}
	else if(obj.keyCode==8||obj.keyCode==37)
	{
	    if(document.location.href.toLowerCase().indexOf("interfaces")>=0)
	        return true;
	    if(targ.tagName.toLowerCase()=="input")
	        return true;
	    if(targ.tagName.toLowerCase()=="textarea")
	        return true;
	    Dipan.SanGuo.PageTo.up();
	    return false;
	}
	else if(obj.keyCode==39)
	{
	    if(document.location.href.toLowerCase().indexOf("interfaces")>=0)
	        return true;
	    if(targ.tagName.toLowerCase()=="input")
	        return true;
	    if(targ.tagName.toLowerCase()=="textarea")
	        return true;
	    Dipan.SanGuo.PageTo.next();
	    return false;
	}
	//return true;
 // window.event.altKey
//window.event.shiftKey    
  } 
Array.prototype.del=function(n) {
if(n<0)
    return this; 
else 
    return this.slice(0,n).concat(this.slice(n+1,this.length)); 
} 
document.onkeydown=__onkeydown;

Dipan.SanGuo.PageTo =
{
    Initialize: function()
    {
    },
    id:-1,
    array:null,
    nowid:-2,
    add:function(_fun)
    {
        if(this.array==null)this.array=new Array();
        if(this.array[this.id]!=_fun)
        {
            this.id++;
            this.array[this.id]=_fun;
            if(this.id<this.array.length-1)
                this.array=this.array.slice(0,this.id+1);
            if(this.array.length>20)
                this.array=this.array.slice(0,30);
            return;
        }
    },
    up:function()
    {
        if(this.array==null)return "";
        if(this.id>0)
        {
           this.id--;
           eval('Dipan.SanGuo.'+this.array[this.id]);
        }
    },
    f5:function()
    {
        if(this.array==null)return "";
        if(this.id>=0)
        {
            eval('Dipan.SanGuo.'+this.array[this.id]);
        }
    },
    next:function()
    {
        if(this.array==null)return "";
        if(this.id<this.array.length-1)
        {
            this.id++;
            eval('Dipan.SanGuo.'+this.array[this.id]);
        }
    },
    show:function()
    {
        alert(Dipan.SanGuo.Common.GetCookie("timeout"));
        return;
        alert('id:'+this.id);
        if(this.array==null)return "";
        var temp="";
        for(i=0;i<this.array.length;i++)
            temp+=this.array[i]+"-";
        alert(temp);
    }
};
function getbiaoshi()
{
	GetData("/interfaces/bookmark.aspx?r="+Math.random(), back_getbiaoshi);	
}
var back_getbiaoshi = function(obj)
{
	firstPost = true;
	var ret = obj.responseText;	
	//$('tran_content').className='messages_float_up';
	if($('_float')!=null)
		document.body.removeChild($('_float'));
	var div1 = document.createElement("DIV");
  div1.id='_float';
  div1.className='float_all';
  div1.style.position = "absolute";
  div1.style.zIndex = "1103754";
  div1.innerHTML = ret;
  document.body.appendChild(div1);
	var zuobiaolist = document.getElementsByName('zuobiao');
	for(var i = 0 ; i < zuobiaolist.length ; i ++)
	{
		zuobiaolist[i].innerHTML="("+Dipan.SanGuo.Common.MapIdToPos(zuobiaolist[i].innerHTML)+")";
	}			
	new Draggable("drag_float", true);	
}
function delbiaoshi(id)
{
    var cf = confirm("确定要删除吗？");
    cf.onClose = function()
    {
        if(cf.returnValue)
        {
            GetData("/interfaces/bookmark.aspx?id="+id+"&r="+Math.random(), back_delbiaoshi);
        }
    }	
}
var back_delbiaoshi = function(obj)
{
	firstPost = true;
	var ret = obj.responseText;	
	if(ret==0)
		getbiaoshi();
	else
		alert('删除失败。');
}
function getjiazu()
{
	GetData("/interfaces/Family.aspx?r="+Math.random(), back_getjiazu);	
}
var back_getjiazu = function(obj)
{
	firstPost = true;
	var ret = obj.responseText;	
	if($('_float')!=null)
		document.body.removeChild($('_float'));
	var div1 = document.createElement("DIV");
  div1.id='_float';
  div1.className='float_all';
  div1.style.position = "absolute";
  div1.style.zIndex = "1103754";
  div1.innerHTML = ret;
  document.body.appendChild(div1);
	if($('tab_time_0')!=null)
	{
		$('tab_time_0').innerHTML=getjiazu_time($('tab_time_0').innerHTML);
	}	
	new Draggable("drag_float", true);	
}
function getjiazu_time(sec)
{
    var str="";
    if(Math.floor(sec/86400)>0)
        str=Math.floor(sec/86400)+"天 ";
    t_1=sec%86400;
    str+=Math.floor(t_1/3600)+":";
    t_2=t_1%3600;
    str+=Math.floor(t_2/60)+":";
    t_3=t_2%60;    
    str+=t_3;
    return str;    
}
function jiazuYS()
{
    var cf = confirm("你需要支付50个元宝。");
    cf.onClose = function()
    {
        if(cf.returnValue)
        {
            Dipan.SanGuo.Oasis.UsePlusFunc(22);
        }
    }
}
function closehelp()
{
    return false;
}
if(document.attachEvent)
{
    window.onhelp=closehelp;
}
window.alert=function(str)   
{
// ondblclick="Effect.Puff(\'_alert\');Effect.Shake(\'_alert\');"
    var temp=['<div class="float_s" id="drop_alert" ondblclick="$(\'_alert\').style.display=\'none\';">',
        '<div class="top">',
        '<span></span></div>',
        '<div class="s_cont">',
        '<div class="main2">',
        '<div class="det yellow4 font12">',
        '<table width="100%" border="0" cellspacing="0" cellpadding="0">',
        '<tr>',
        '<td>${txt}</td>',
        '</tr>',
        '<tr>',
        '<td ><div class="smallpage"><a class="bun_n but_12" href="#" onclick="$(\'_alert\').style.display=\'none\';return false;">关闭</a></div></td>',
        '</tr>',
        '</table>',
        '</div>',
        '<div class="clear">',
        '</div>',
        '</div>',
        '</div>',
        '<div class="bottom">',
        '<span></span></div>',
        '</div>'];
    //var temp=['<div class="smallpage" ondblclick="Effect.Puff(\'_alert\');Effect.Shake(\'_alert\');"><div class="smallpage_w"><div class="smallpage_t" id="drop_alert">双击关闭</div><div class="smallpage_n">${txt}</div><div class="smallpage_c"><a href="#" onclick="Effect.Puff(\'_alert\');Effect.Shake(\'_alert\');return false;" class="sc">[关闭]</a></div></div></div>'];
    Dipan.SanGuo.Common.FixData(temp, "_alert", {txt:str}, true);
    var d=$('_alert');
    d.style.cssText = "position:absolute; z-index:5103757";
    //new Effect.BlindDown("_alert");
    new Draggable("drop_alert", true);
    //new Effect.Pulsate('_alert', {pulses: 3})
}

window.confirm=function(str,width,height,withCancel)   
{
    var topWin = window.top;
	if(topWin.sConfirmHandle!=null){
		return topWin.sConfirmHandle;
	}
	if(width==null)
		width = 255;
	if(height==null)
		height = 70;
	
	if(topWin.sConfirmId==null)
		topWin.sConfirmId = 0;
	topWin.sConfirmId++;
	var doc = topWin.document;
        
    var temp=['<div class="float_s" id="drop_alert" ondblclick="$(\'_alert\').style.display=\'none\';">',
        '<div class="top">',
        '<span></span></div>',
        '<div class="s_cont" align="center">',
        '<iframe id="frame_drop_alert" width="'+(width)+'" height="'+(height)+'" frameborder="0" scrolling="no" src="/@/Htmls/confirm.html" ></iframe>',
        '</div>',
        '<div class="bottom">',
        '<span></span></div>',
        '</div>'];
    
    Dipan.SanGuo.Common.FixData(temp, "_alert", {txt:str}, true);
    var d=$('_alert');
    d.style.cssText = "position:absolute; z-index:56758353";
    new Draggable("drop_alert", true);
    
    var handle = new SigmaConfirmHandle();
	handle.id = "drop_alert";
	handle.content = str;
	handle.width = width;
	handle.height = height;
	handle.withCancel = withCancel;
	topWin.sConfirmHandle = handle;
	
	return handle;
}

/*获得当前窗口尺寸和页面尺寸*/
function _getPageSize(){
	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) { 
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	}else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	}else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) { // all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	}else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	} 

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){ 
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

/*获得页面当前滚动偏移量*/
function _getScrollOffset()
{
	var posX,posY;  
    if (window.innerHeight) {  
        posX = window.pageXOffset;  
        posY = window.pageYOffset;  
    }else if (document.documentElement && document.documentElement.scrollTop) {  
        posX = document.documentElement.scrollLeft;  
        posY = document.documentElement.scrollTop;  
    }else if (document.body) {  
        posX = document.body.scrollLeft;  
        posY = document.body.scrollTop;  
    }
	var r = [];
	r[0] = posX;
	r[1] = posY;
	return r;
}

function isIE()
{
    if(navigator.appVersion.indexOf("MSIE")>=0){
        return true;
    }else{
        return false;
    }
}

function GetJsParam(paramName)   
{   
	var reg = new RegExp("(^|\\?|&)"+ paramName+"=([^&]*)(\\s|&|$)", "i");
	if (reg.test($("globaljs").src))
	{
		return RegExp.$2;
	}
	else
	{
		return "";
	}
}

function SigmaConfirmHandle(){
	this.id = null;
	this.onClose = function(){}
	this.returnValue = null;
	this.getFrame = function(){
		return document.getElementById("frame_drop_alert");
	}
}

Array.prototype.remove=function(dx) 
{ 
if(isNaN(dx)||dx>this.length){return false;} 
for(var i=0,n=0;i<this.length;i++) 
{ 
if(this[i]!=this[dx]) 
{ 
this[n++]=this[i] 
} 
} 
this.length-=1 
}

function trace(info)
{
    var div = document.createElement("DIV");
    div.innerHTML = info;
    document.body.appendChild(div);
}